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 }
  • 相关阅读:
    爬虫的简单运用
    预测体育竞技比赛结果(新人练手)
    自己的第一个网页
    科学计算和可视化(numpy及matplotlib学习笔记)
    面向对象总结
    PIL库的总结及运用
    jirba库的使用和好玩的词云
    第一次结队作业
    四则运算版本升级
    自动生成小学四则运算项目练习(已更新)
  • 原文地址:https://www.cnblogs.com/cypress/p/7838355.html
Copyright © 2011-2022 走看看