本文系摘抄:
a.txt 内容 01234567890
BufferedInputStream in = new BufferedInputStream(new FileInputStream(
new File("a.txt")),8);
int s = -1;
// String str = "";
int count = 0;
while ((s = in.read()) != -1) {
System.out.print((char) s);
if (count == 4) {
in.mark(12);
break;
}
s = -1;
count++;
}
System.out.println();
in.reset();
while ((s = in.read()) != -1) {
System.out.print((char) s);
}
System.out.println();
in.reset();
while ((s = in.read()) != -1) {
System.out.print((char) s);
}
System.out.println();
in.close();
mark(int readlimit);
在mark后再read,如果读到的字节数大于BufferedInputStream缓冲区大小,那么你就再不能回到标记的位置,而readlimit如果大于BufferedInputStream缓冲区大小,那么BufferedInputStream会重置缓冲大小为readlimit;