输入输出流copy文件

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");
}
}

posted @ 2017-08-16 19:34  骑着猪猛跑  阅读(180)  评论(0编辑  收藏  举报