我正在尝试读取输入流两次。但是当我尝试重置流并读取它时说没有字节read.i从inputstream更改为bufferedinputstream仍然重置对我不起作用。可能是我正在做的错误?下面是我的代码:
byte[] buffer = new byte[READ_BUFFER_SIZE];
int bytesRead=0;
InputStream _baseStream = new FileInputStream("slot.txt");
BufferedInputStream buff =new BufferedInputStream(_baseStream);
try {
bytesRead = buff.read(buffer, 0, READ_BUFFER_SIZE);
System.out.println("1. "+bytesRead);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(bytesRead>0)
{
buff.mark(10);
buff.reset();
try {
//bytesRead = _baseStream.read(buffer, 0, READ_BUFFER_SIZE);
bytesRead = buff.read(buffer, 0, READ_BUFFER_SIZE);
System.out.println("2. "+bytesRead);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
输出 1. 39 2. -1