- /**
- * 导入
- * @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();
- }
- }
- }
【本文是51CTO专栏作者张勇波的原创文章,转载请通过51CTO获取作者授权】