复制文件:
private void copyFile(File in, File out) {
try {
FileChannel sourceChannel = new FileInputStream(in).getChannel();
FileChannel destinationChannel = new FileOutputStream(out)
.getChannel();
sourceChannel.transferTo(0, sourceChannel.size(),
destinationChannel);
// or
// destinationChannel.transferFrom(sourceChannel, 0,
// sourceChannel.size());
sourceChannel.close();
destinationChannel.close();
sourceChannel = null;
destinationChannel = null;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
移动文件:
private void movefile(String srcFile, String destPath) {
File oldfile = new File(srcFile);
File newpath = new File(destPath);
if (!newpath.exists()) {
newpath.mkdirs();
}
File newfile = new File(destPath, oldfile.getName());
oldfile.renameTo(newfile);
}