我爱学习_33
2017-03-17 09:07:28浏览 2438
输入代码
```package demo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyDemo {
public void copy(File file) throws IOException{
if(file.exists()==false){
System.out.println("该路径不存在");
}
File fi[]=file.listFiles();
if (fi != null &&fi.length>0 ){
for (File cfile : fi) {
if(cfile.isDirectory()){
copy(cfile);
}else{
@SuppressWarnings("resource")
FileInputStream fis=new FileInputStream(cfile);
String cmd=cfile.getName();
@SuppressWarnings("resource")
FileOutputStream fos=new FileOutputStream("F:\\"+cmd);
int b=0;
byte [] arr= new byte [1024*2];
while (( b=fis.read(arr) )!=-1){
fos.write(arr,0,b);
fos.flush();
}
fos.close();
fis.close();
}
}
}
}
public static void main(String[] args) throws IOException {
CopyDemo demo=new CopyDemo();
File file=new File("E:\\java");
demo.copy(file);
}
}