java操纵硬件的copy文件的小问题??
我现在想把E:/a.txt 文件copy到D:/下 成为D:/a.txt 结果是D:/下也有a.txt,E:/下也有a.txt ,我现在不想用/Runtime.getRuntime().exec( " ")来做。感觉不可靠,希望大虾帮我啊!
------解决方案--------------------// 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();
}