public class readarr {
public static void main(String[] args) throws IOException {
//1.指定源文件
FileInputStream fr = new FileInputStream("demo1.txt");
//2.指定目标文件
FileOutputStream fw = new FileOutputStream("demo3.txt");
//3.字节数组读取1次的个数
byte[] bs = new byte[1024];
//4.循环读取
while ((int len = fr.read(bs)) != -1) {
System.out.println(new String(bs, 0, len));
//每次写入读取的内容
fw.write(bs, 0, len);
}
//5.关闭流
fw.close();
fr.close();
}
}
10.IO的文件拷贝
最新推荐文章于 2023-12-06 15:19:19 发布