• java复制文件


     1 /**
     2      * @param sourceFile
     3      * @param targetFile
     4      * @throws IOException
     5      */
     6     public static void copyFile(File sourceFile, File targetFile)
     7             throws IOException {
     8         BufferedInputStream inBuff = null;
     9         BufferedOutputStream outBuff = null;
    10         try {
    11             inBuff = new BufferedInputStream(new FileInputStream(sourceFile));
    12             outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));
    13 
    14             byte[] b = new byte[1024 * 1024];
    15             int len;
    16             while ((len = inBuff.read(b)) != -1) {
    17                 outBuff.write(b, 0, len);
    18             }
    19             outBuff.flush();
    20         } finally {
    21             if (inBuff != null)
    22                 inBuff.close();
    23             if (outBuff != null)
    24                 outBuff.close();
    25         }
    26     }
  • 相关阅读:
    eclipse中包的位置
    404代码错误解决
    servlet-web.xml配置
    java web.xml配置servlet
    1031整理
    1030整理
    rownum
    存储过程和自定义函数的区别
    课堂整理
    练习
  • 原文地址:https://www.cnblogs.com/akatuki/p/4045991.html
Copyright © 2020-2023  润新知