用字节流来复制文本文件

 1 import java.io.FileInputStream;
 2 import java.io.FileOutputStream;
 3 import java.io.IOException;
 4 /*
 5  * 用字节流来复制文本文件
 6  */
 7 public class CopyTextFile {
 8 
 9     public static void main(String[] args) throws IOException {
10         //创建FileInputStream对象(源文件路径)
11         FileInputStream in = new FileInputStream("D:\\textFile.txt");
12         
13         //创建FileOutputStream对象(目标路径)
14         FileOutputStream out = new FileOutputStream("E:\\textFile.txt");
15         
16         //进行复制
17         int len = 0; //记录每一次读到的长度
18         byte[] byts = new byte[1024];  //容器
19         while ((len = in.read(byts)) != -1) {
20             out.write(byts, 0, len);
21         }
22         
23         //释放资源
24         in.close();
25         out.close();
26     }
27 }

猜你喜欢

转载自www.cnblogs.com/li1234567980/p/10952334.html
今日推荐