java 实现拷贝文件的例子(从网上摘来的)。
This example uses file streams to copy the contents of one file to another file. See e172 Copying One File to Another for an example that uses file channels.
// Copies src file to dst file.
// If the dst file does not exist, it is created
void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
调用时:copy(new File("D://temp//1//1.txt"), new File("D://temp//2//1.txt"));