import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class selfcopy {
public void IOCopy(String path,String path1){
File file = new File(path);
File file1 = new File(path1);
if(!file.exists()){
System.out.println(file.getName()+"文件不存在");
}else{
System.out.println("存在");
}
byte[] b = new byte[(int) file.length()];
if(file.isFile()){
try {
FileInputStream is= new FileInputStream(file);
FileOutputStream ps= new FileOutputStream(file1);
is.read(b);
ps.write(b);
} catch (Exception e) {
e.printStackTrace();
}
}else if(file.isDirectory()){
if(!file.exists())
file.mkdir();
String[] list = file.list();
for(int i=0;i<list.length;i++){
this.IOCopy(path+"/"+list[i], path1+"/"+list[i]);
}
}
}
public static void main(String args[]){
new selfcopy().IOCopy("D:\\device","D:\\TDDOWNLOAD");
}
}
将一个文件夹下的所有文件复制到另一个文件夹下
最新推荐文章于 2022-06-23 07:51:36 发布