public String readFile() throws IOException
{
File rFile = new File("c:/jdk1.5.0_14.rar");
File wFile = new File("e:/jdk1.5.0_16.rar");
try {
FileInputStream iReader = new FileInputStream(rFile);
FileOutputStream oWriter = new FileOutputStream(wFile);
int off = 0;
int length = 1024;
byte[] buff = new byte[length];
// 注意:读出1024字节写入1024字节
while((off=iReader.read(buff,0,length)) !=-1)
{
oWriter.write(buff);
}
oWriter.flush();
oWriter.close();
iReader.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(FileIO.class.getName()).log(Level.SEVERE, null, ex);
}
return "success";
}
本文提供了一个使用Java进行文件复制的示例代码,演示了如何通过FileInputStream和FileOutputStream实现从一个位置到另一个位置的文件复制过程。
605

被折叠的 条评论
为什么被折叠?



