黑马程序员技术交流社区

标题: 急急。是不是电脑的锅? [打印本页]

作者: 小十    时间: 2015-3-15 14:04
标题: 急急。是不是电脑的锅?
  1. import java.io.BufferedInputStream;
  2. import java.io.BufferedOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.FilenameFilter;
  8. import java.io.IOException;
  9. import java.io.InputStream;

  10. public class copy2 {

  11.         /**
  12.          * 把某盘中的一个多层文件夹拷贝到某盘中。用高效的方法
  13.          *
  14.          * @param args
  15.          * @throws IOException
  16.          */
  17.         public static void main(String[] args) throws IOException {
  18.                 // TODO Auto-generated method stub
  19.                 File yuan = new File("e:\\qwer");
  20.                 File mudi = new File("f:\\qwer");

  21.                 copyfile(yuan,mudi);
  22.         }

  23.         private static void copyfile(File yuan, File mudi) throws IOException {
  24.                 // TODO Auto-generated method stub
  25.                 File[] file = yuan.listFiles();
  26.                 for(File f : file){
  27.                         //System.out.println(f);
  28.                         /*File yuandir =yuan;
  29.                         File mudidir = mudi;*/
  30.                         if(f.isDirectory()){
  31.                                 File yuandir = new File(yuan+"\\"+f.getName());
  32.                                 File mudidir = new File(mudi+"\\"+f.getName());
  33.                                 copyfile(yuandir,mudidir);
  34.                         }
  35.                         else{
  36.                                 File yuanfile = new File(yuan+"\\"+f.getName());
  37.                                 File mudifile = new File(mudi+"\\"+f.getName());
  38.                                 mudi.mkdirs();
  39.                                 copyoi(yuanfile,mudifile);
  40.                         }
  41.                 }
  42.                
  43.         }

  44.         private static void copyoi(File yuandir, File mudidir) throws IOException {
  45.                 // TODO Auto-generated method stub
  46.                 BufferedInputStream bufin = new BufferedInputStream(new FileInputStream(yuandir));
  47.                 BufferedOutputStream bufou = new BufferedOutputStream(new FileOutputStream(mudidir));
  48.                 byte[] buf = new byte[1024];
  49.                 int line =0;
  50.                 while((line = bufin.read(buf))!=-1){
  51.                         bufou.write(buf,0,line);
  52.                         bufou.flush();
  53.                 }
  54.                 bufin.close();
  55.                 bufou.close();
  56.                
  57.         }

  58. }
复制代码

是代码的问题吗?不是的话我真的是怀疑我的电脑了求解...
作者: Shey    时间: 2015-3-15 14:11
你问题还没说呢




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2