JAVA 复制文件内容到另一个文件

 1 package io.test;
 2 
 3 import java.io.*;
 4 
 5 public class InputDemo {
 6     public static void main(String[] args) throws IOException {
 7         //将一个文件内容写入到另一个文件中
 8         File file = new File("./1.txt");
 9         FileInputStream fileInputStream = new FileInputStream(file);
10         FileOutputStream fileOutputStream = new FileOutputStream("./2.txt");
11         int by;
12         while ((by=fileInputStream.read())!=-1){
13             fileOutputStream.write(by);
14         }
15         fileOutputStream.close();
16     }
17 }

 

posted @ 2022-03-28 18:09  phpwyl  阅读(304)  评论(0编辑  收藏  举报