private void CopyFile(File originf,File clonef) throws IOException{
int length=65535; //根据具体情况而定的文件长度
FileInputStream in=new FileInputStream(originf);
FileOutputStream out=new FileOutputStream(clonef);
byte[] buf=new byte[length];
while(true){
int num=in.read(buf);
if(ins==-1){
in.close();
out.flush();
out.close();
}else
out.write(buffer,0,num);
}
}

本文详细介绍了使用Java实现文件复制的算法,包括使用FileInputStream和FileOutputStream进行读写操作,通过循环读取文件内容并复制到目标文件。适用于对文件复制机制感兴趣的开发者。
3860

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



