/**
* 文件拷贝,字节批量读取
* @param srcFile
* @param destFile
* @throws IOException
*/
public static void copyFile(File srcFile,File destFile)throws IOException{//流一般都有io错误
if(!srcFile.exists()){
throw new IllegalArgumentException(“文件:”+srcFile+”不存在”);
}
if(!srcFile.isFile()){
throw new IllegalArgumentException(srcFile+”不是文件”);
}
FileInputStream in = new FileInputStream(srcFile);//读取 srcFile里的文件
FileOutputStream out = new FileOutputStream(destFile);//写入destFile中
byte[] buf = new byte[8*1024];
int b ;
while((b = in.read(buf,0,buf.length))!=-1){//读到buf中
out.write(buf);//写入
out.flush();//最好加上刷新
}
in.close();
out.close();
}
public static void main(String[] args) {
try {
copyFile(new File(“D:\test\rat.src”), new File(“D:\test\rat.src”));//要用类名调用
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}