java文件复制

 1 //文件复制
 2 package IO;
 3 import java.io.File;
 4 import java.io.FileInputStream;
 5 import java.io.IOException;
 6 import java.io.InputStream;
 7 import java.io.PrintWriter;
 8 
 9 public class InputStreamDemo {
10 
11     public static void main(String[] args) {
12           InputStream in=null;
13           //in=new FileInputStream(new File("d:/abc.txt"));
14           File f=new File("d:/abc_1.txt");
15           try {
16             PrintWriter pw=new PrintWriter(f);
17             in = new FileInputStream("d://abc.txt");
18             //System.out.println(in.available());//file.length()
19             byte[] buf=new byte[in.available()];
20             in.read(buf);//将文件abc.txt内容读取到buf中
21             //buf :byte[]->String        
22             pw.println(new String(buf));
23             pw.close();
24         } catch (Exception e) {
25             
26             e.printStackTrace();
27         }finally {
28             try {
29                 in.close();
30             } catch (IOException e) {
31                 e.printStackTrace();
32             }
33         }
34           
35     }
36 
37 }

 

posted @ 2020-12-20 00:04  丁帅帅dss  阅读(83)  评论(0)    收藏  举报