FileChannel进行文件复制

FileChannel进行文件复制

/** 
 * 导入 
 * @param urlPath 附件相对路径(xml存储路径) 
 * @param path 项目绝对路径 
 * @param keyID 要导出信息的keyID 
 * @param filepath 导入后路径 
 */  
private static void importCopy(String urlPath, String path, String keyID, String filepath) {  
    // 生成目录  
    File f = new File(path + filepath);  
    if (!f.exists()) {  
        f.mkdirs();  
    }  
    String filename = urlPath.substring(urlPath.lastIndexOf("/") + 1);  
    FileInputStream fi = null;  
    FileOutputStream fo = null;  
    FileChannel in = null;  
    FileChannel out = null;  
    try {  
        fi = new FileInputStream(path + "/imp/" + keyID + "/" + filename);  //源文件
        fo = new FileOutputStream(path + filepath + filename);  //导入后文件
        in = fi.getChannel();// 得到对应的文件通道  
        out = fo.getChannel();// 得到对应的文件通道  
        in.transferTo(0, in.size(), out);// 连接两个通道,并且从in通道读取,然后写入out通道  
    } catch (IOException e) {  
        e.printStackTrace();  
    } finally {  
        try {  
            fi.close();  
            in.close();  
            fo.close();  
            out.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}  

 上一篇
Excel表格转html Excel表格转html
Excel表格转htmlimport org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.
2019-08-19
下一篇 
FreeMarker内建函数介绍 FreeMarker内建函数介绍
FreeMarker内建函数介绍Sequence的内置函数sequence?first 返回sequence的第一个值。 sequence?last 返回sequence的最后一个值。 sequence?reverse 将sequence的
2019-08-19
  目录