其他分享
首页 > 其他分享> > 文件复制

文件复制

作者:互联网

其实也很简单就是索取文件地址 得到文件内容 在指定地址新建文件 将得到的内容写进文件中而已
写一个方法
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);
}
}
}
}

标签:文件,target,bys,复制,File,new,dir
来源: https://www.cnblogs.com/sk244/p/12779012.html