zoukankan      html  css  js  c++  java
  • 复制单级目录

    1.1.1 复制单级文件夹

    /*

     * 数据源:e:\demo

     * 目的地:e:\test

     *

     * 分析:

     * A:封装目录

     * B:获取该目录下的所有文本的File数组

     * C:遍历该File数组,得到每一个File对象

     * D:把该File进行复制

     */

    public class CopyFolderDemo {

    public static void main(String[] args) throws IOException {

    // 封装目录

    File srcFolder = new File("e:\demo");

    // 封装目的地

    File destFolder = new File("e:\test");

    // 如果目的地文件夹不存在,就创建

    if (!destFolder.exists()) {

    destFolder.mkdir();

    }

    // 获取该目录下的所有文本的File数组

    File[] fileArray = srcFolder.listFiles();

    // 遍历该File数组,得到每一个File对象

    for (File file : fileArray) {

    // System.out.println(file);

    // 数据源:e:\demo\e.mp3

    // 目的地:e:\test\e.mp3

    String name = file.getName(); // e.mp3

    File newFile = new File(destFolder, name); // e:\test\e.mp3  拼接新的目录

    copyFile(file, newFile);

    }

    }

    private static void copyFile(File file, File newFile) throws IOException {

    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(

    file));

    BufferedOutputStream bos = new BufferedOutputStream(

    new FileOutputStream(newFile));

    byte[] bys = new byte[1024];

    int len = 0;

    while ((len = bis.read(bys)) != -1) {

    bos.write(bys, 0, len);

    }

    bos.close();

    bis.close();

    }

    }

  • 相关阅读:
    Mac ssh登陆linux并且显示linux图形
    github proxy
    [makefile] filter-out
    linux svn
    界面UI测试的方法
    UI测试
    web 页面中 四种常见 必测控件
    面试工作经验参考
    测试用例
    接口测试基础
  • 原文地址:https://www.cnblogs.com/shan1393/p/8964701.html
Copyright © 2011-2022 走看看