游客发表

FileChannel进行文件复制

发帖时间:2025-11-05 08:55:44

 

/**  * 导入  * @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();  }  } } 

【本文是进件复专栏作者张勇波的高防服务器原创文章,转载请通过获取作者授权】

行文

    热门排行

    友情链接