首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java操纵硬件的copy文件的小疑点?

2012-01-15 
java操纵硬件的copy文件的小问题??我现在想把E:/a.txt文件copy到D:/下成为D:/a.txt结果是D:/下也有a.txt,E

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();
}

热点排行
Bad Request.