zoukankan      html  css  js  c++  java
  • IO查找文件复制到指定路径

     1 public class IOTest {
     2     // 存储获取的文件绝对路径
     3     private static List<String> list = new ArrayList<String>();
     4     public static void main(String[] args) {
     5         File file = new File("D:/holle");
     6         Long sta = System.currentTimeMillis();
     7         mkdirAll(file);
     8         for(String str : list){
     9             String[] split = str.split("\\\\");
    10             try {
    11                 IO(str, "D:/"+split[split.length-1]);
    12             } catch (IOException e) {
    13                 e.printStackTrace();
    14             }
    15         }
    16         Long end = System.currentTimeMillis();
    17         System.out.println("用时"+(end-sta));
    18     }
    19     
    20     
    21     private static void mkdirAll(File file){
    22         File[] f = file.listFiles();
    23         for (File file2 : f) {
    24             // 递归算法,如果有子文件夹继续向下查找
    25             if(file2.isDirectory()){
    26                 mkdirAll(file2);
    27             }else{
    28                 list.add(file2.toString());
    29             }
    30         }
    31     }
    32     
    33     public static void IO(String file,String newFile)throws IOException{
    34         //
    35         File f1 = new File(file);
    36         File f2 = new File(newFile);
    37         //
    38         FileInputStream fis = new FileInputStream(f1);
    39         FileOutputStream fos = new FileOutputStream(f2);
    40         //
    41         byte[] data = new byte[1024 * 1024];
    42         //
    43         int len = 0;
    44         while((len = fis.read(data)) != -1){
    45             fos.write(data, 0, len);
    46         }
    47         //
    48         fis.close();
    49         fos.close();    
    50     }
    51 }
  • 相关阅读:
    Navicat 导出sql问题
    2017,我的第一次年终总结
    dev treelist和searchcontrol组合模糊查询用法
    构造函数详解
    Devexpress常见问题
    Devexpress 常用的功能
    dev Gridcontrol控件属性部分
    记录DEV gridview获取行列数据方法
    string类的几种方法
    plsql中的procedure和function编程
  • 原文地址:https://www.cnblogs.com/cypress/p/7838355.html
Copyright © 2011-2022 走看看