import java.io.*;
public class CopeFile {
public static void main(String[] args) throws Exception{
File fi1=null;
File fi2=null;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true){
System.out.println("输入源文件夹路径:");
fi1=new File(br.readLine());
if(!(fi1.exists())){
System.out.println("无此文件夹路径");
continue;
}
System.out.println("输入目标文件夹路径:");
fi2=new File(br.readLine());
if(!(fi2.exists())){
System.out.println("无此文件夹路径");
continue;
}
break;
}
copy(fi1.listFiles(),fi2);
}
public static void copy(File[] fiarr,File fi) throws Exception{
for(int i=0;i<fiarr.length;i++){
if(fiarr[i].isFile()){
BufferedInputStream bi=new BufferedInputStream(new FileInputStream(fiarr[i]));
BufferedOutputStream bo=new BufferedOutputStream(new FileOutputStream(fi.getCanonicalPath()+"\\"+fiarr[i].getName()));
byte[] b=new byte[2048];
int len=0;
while((len=bi.read(b))!=-1){
bo.write(b, 0, len);
}
bi.close();
bo.close();
}
}
System.out.println("复制成功!!!!!");
}
}
|