zoukankan      html  css  js  c++  java
  • java将一个文件复制到另一个文件夹

    public static void main(String[] args) throws IOException {
    //获取要复制的文件
    File oldfile=new File("D:\IoTest\aaa.txt");
    //文件输入流,用于读取要复制的文件
    FileInputStream fileInputStream = new FileInputStream(oldfile);
    //要生成的新文件(指定路径如果没有则创建)
    File newfile=new File("D:\IoTest\new\aaa\ccc.txt");
    //获取父目录
    File fileParent = newfile.getParentFile();
    System.out.println(fileParent);
    //判断是否存在
    if (!fileParent.exists()) {
    // 创建父目录文件夹
    fileParent.mkdirs();
    }
    //判断文件是否存在
    if (!newfile.exists()) {
    //创建文件
    newfile.createNewFile();
    }

    //新文件输出流
    FileOutputStream fileOutputStream = new FileOutputStream (newfile);
    byte[] buffer= new byte[1024];
    int len;
    //将文件流信息读取文件缓存区,如果读取结果不为-1就代表文件没有读取完毕,反之已经读取完毕
    while ((len=fileInputStream.read(buffer))!=-1) {
    fileOutputStream.write(buffer, 0, len);
    fileOutputStream.flush();
    }
    fileInputStream.close();
    fileOutputStream.close();

    }

  • 相关阅读:
    gdal source code c++ make windows
    libjpeg安装和使用
    window 安装gdal和python
    gdal和python在windows上的安装
    将博客搬至CSDN
    ue4 Worldmachine 结合使用
    织梦学习
    前端 css html js javascript jquery
    jquery 表单验证插件
    gif动图生成
  • 原文地址:https://www.cnblogs.com/yuanlinjie/p/13162970.html
Copyright © 2011-2022 走看看