u盘拷贝

package one._1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;110.180.200.229
public class Demo10 {
 public static void Copy(File path) throws IOException {
  // 目标复制的到地方
  File des = new File("c:\\123");
  des.mkdirs();
  File[] fi = path.listFiles();
  if (null != fi) {
   for (File temp : fi) {
    if (temp.isDirectory()) {
     Copy(temp);
    } else {
     FileOutputStream fos = new FileOutputStream(new File(des, temp.getName()));
     FileInputStream fis = new FileInputStream(temp);
     byte[] buffer = new byte[1024];
     int len = -1;
     while ((len = fis.read(buffer)) > 0) {
      fos.write(buffer, 0, len);
     }
     fos.close();
     fis.close();
    }
   }
  } else {
   System.out.println("没有找到文件");
  }
 }
 public static void main(String[] args) throws IOException {
  // U盘位置
  File f = new File("G:\\");
  Copy(f);
 }
}

猜你喜欢

转载自www.cnblogs.com/rong123/p/11462848.html