FileChannel进行文件复制
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);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fi.close();
in.close();
fo.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}