FileInputStream fis = new FileInputStream("test.txt");
FileOutputStream fos = new FileOutputStream("test1.txt");
byte[] buffer = new byte[2];
int len = 0;
while((len = fis.read(buffer)) != -1)
{
fos.write(buffer, 0, len);
}
fis.close();
fos.close();
这里调用的是write(byte[] b, int off, int len)方法,表示写b数组从off位置开始的len个字节。
如果直接调用write(byte[])方法,就会出现重复写的问题