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();
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章