我想使用bufferedInputStream
并将bufferedOutputStream
大型二进制文件从源文件复制到目标文件。
这是我的代码:
byte[] buffer = new byte[1000];
try {
FileInputStream fis = new FileInputStream(args[0]);
BufferedInputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream(args[1]);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int numBytes;
while ((numBytes = bis.read(buffer))!= -1)
{
bos.write(buffer);
}
//bos.flush();
//bos.write("\u001a");
System.out.println(args[0]+ " is successfully copied to "+args[1]);
bis.close();
bos.close();
} catch (IOException e)
{
e.printStackTrace();
}
我可以成功复制,但后来我使用
cmp src dest
在命令行中比较两个文件。错误信息
cmp:文件的EOF
出现。我可以知道我错在哪里吗?