首页 > 其他 > 详细

输入输出流copy文件

时间:2017-08-16 19:41:37      阅读:175      评论:0      收藏:0      [点我收藏+]

public class asd {
private static void customBufferStreamCopy(String source, String target) {

InputStream fis = null;
OutputStream fos = null;
try {
fis = new FileInputStream(source);
fos = new FileOutputStream(target);
byte[] buf = new byte[4096];
int i;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
}
catch (Exception e) {
e.printStackTrace(); }
finally {
try {
fis.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
public static void main(String[] args) {

File f=new File("C:/Users/Administrator/Desktop/biji4.txt");
if(f.exists()){}
else {
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
new asd();
asd.customBufferStreamCopy("C:/Users/Administrator/Desktop/biji4.txt", "C:/Users/Administrator/Desktop/biji3.txt");
}
}

输入输出流copy文件

原文:http://www.cnblogs.com/zhaosong-0102/p/7375331.html

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