java初学(六)文件读写 复制文件 IO流

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_41359651/article/details/100169736
package cn.wan;



import java.io.*;


public class Main {
    public static void main(String[] args) throws IOException {
        /*FileOutputStream fileOutputStream = new FileOutputStream("text.txt");
        for (int i = 0; i < 2048; i++) {
            fileOutputStream.write(i % 94 + 33);
        }
        fileOutputStream.close();*/

        FileInputStream fileInputStream = new FileInputStream("C:/Users/39657/Desktop/page1.png");
        FileOutputStream fileOutputStream = new FileOutputStream("page1.png");
        byte[] bytes = new byte[1024];
        while (true) {
            int len = fileInputStream.read(bytes);
            System.out.println(len);
            if (len != -1) {
                fileOutputStream.write(bytes);
            } else {
                break;
            }
        }
        fileOutputStream.close();
        fileInputStream.close();
    }

}

猜你喜欢

转载自blog.csdn.net/qq_41359651/article/details/100169736