输入输出流copy文件
Posted 骑着猪猛跑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了输入输出流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");
}
}
以上是关于输入输出流copy文件的主要内容,如果未能解决你的问题,请参考以下文章