FileOutputStreamTest
public class FileOutputStreamTest
{
?? ?public static void main(String[] args)
?? ?{
?? ??? ?try (
?? ??? ??? ?// 創建字節輸入流
?? ??? ??? ?var fis = new FileInputStream("FileOutputStreamTest.java");
?? ??? ??? ?// 創建字節輸出流
?? ??? ??? ?var fos = new FileOutputStream("newFile.txt"))
?? ??? ?{
?? ??? ??? ?var bbuf = new byte[32];
?? ??? ??? ?var hasRead = 0;
?? ??? ??? ?// 循環從輸入流中取出數據
?? ??? ??? ?while ((hasRead = fis.read(bbuf)) > 0)
?? ??? ??? ?{
?? ??? ??? ??? ?// 每讀取一次,即寫入文件輸出流,讀了多少,就寫多少。
?? ??? ??? ??? ?fos.write(bbuf, 0, hasRead);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?catch (IOException ioe)
?? ??? ?{
?? ??? ??? ?ioe.printStackTrace();
?? ??? ?}
?? ?}
}
?
總結
以上是生活随笔為你收集整理的FileOutputStreamTest的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 日期格式转换:String 与 date
- 下一篇: Action 跳转的方法和详解