文件复制

其实也很简单就是索取文件地址 得到文件内容 在指定地址新建文件 将得到的内容写进文件中而已
写一个方法
public static void copyFile(File target,File dir)
{
InputStream in = null;//输入流建立
OutputStream out = null;输出流建立
File file = null; 中转文件
if(!dir.exist())//判断文件路径是否存在
{
dir.makdirs(); //创建目录
int count = 0;
byte [] bys = new byte[299];//输入所用字节数组
if(target.exist())//如果文件存在
{
String s = target.getName();
file = new File(dir + "/" + s);
in =new FileInputStream(target); // 这里面会有很多异常处理 太繁琐 就不写了 但是eclipse中会报错 点击错误 之后 一键调出就可以
out= new FileOutpuStream(file);
while((count = in.read(bys,0,bys.length))!=-1)
{
out.write(bys,0,count);
}
}
}
}

posted on 2020-04-26 13:44  苏阔Garrison  阅读(81)  评论(0编辑  收藏  举报

导航