首页 > 编程语言 > 详细

java文件复制

时间:2020-12-20 10:46:13      阅读:25      评论:0      收藏:0      [点我收藏+]
 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 }

 

java文件复制

原文:https://www.cnblogs.com/dss-99/p/14162234.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!