learning java FileOutputStream

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutputStreamTest {
    public static void main(String[] args) {
        try {
            var fis = new FileInputStream("FileInputStreamTest.java");
            var fos = new FileOutputStream("output.txt");
            {
                var buf = new byte[32];
                var hasRead = 0;
                while ((hasRead = fis.read(buf)) > 0){
                    fos.write(buf, 0, hasRead);
                }
            }
            fis.close();
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

posted @ 2019-08-05 13:12  嵌入式实操  阅读(82)  评论(0编辑  收藏  举报