利用字节流拷贝文件

public class FileCopy {
    
    
    public static void main(String[] args) throws IOException {
    
    
        // 输入流
        FileInputStream fileInputStream = new FileInputStream(new File("D:\\abc.txt"));
        // 输出流
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\abc(字节方式).txt");
        // 缓冲区(每次读10字节)
        byte[] bytes = new byte[10];
        // 写到文件中
        int length;
        while((length = fileInputStream.read(bytes)) != -1){
    
    
            System.out.println(new String(bytes));
            fileOutputStream.write(bytes, 0, length);
        }

        // 关闭流
        fileOutputStream.close();
        fileInputStream.close();

    }
}

猜你喜欢

转载自blog.csdn.net/m0_46218511/article/details/107715375