public static void main(String[] args) throws IOException{
File aa = new File("e:/111");
File bb= new File("F:/");
copydloe(aa,bb);
}
private static void copydloe(File aa, File bb) throws IOException{
String name = aa.getName();
File cc =new File(bb,name);
if(!cc.isDirectory()){
cc.mkdir();
}
File[] files = aa.listFiles();
for(File f:files){
if(f.isDirectory()){
copydloe(f,cc);
}else {
File ff=new File(cc,f.getName());
copy(f,ff);
}
}
}
private static void copy(File f, File ff) throws IOException {
BufferedReader br =new BufferedReader(new FileReader(f));
BufferedWriter bw = new BufferedWriter(new FileWriter(ff));
String in ;
while ((in = br.readLine())!=null){
bw.write(in);
}
br.close();
bw.close();
}
}
|
|