缓冲的 reader 如何知道要读取哪一行?
How does a buffered reader know what line to read?
在 while/for 循环中,我们使用缓冲的 readers,然后将其附加到字符串生成器中。但是由于我们没有提供一些线路参考编号,同一行不会被反复阅读。
其他详细信息:缓冲的 reader 包装在输入流 Reader 中,我说的是 Java(Android)
String line = reader.readLine();
while (line != null) {
output.append(line);
line = reader.readLine();
}
当您读取文件时,有一个指针指向文件中的下一个读取位置。每次调用 readLine
时,指针都会继续移动,直到它看到 \r\n
或 \n
。然后指针停留在这里供您下次阅读。
在 while/for 循环中,我们使用缓冲的 readers,然后将其附加到字符串生成器中。但是由于我们没有提供一些线路参考编号,同一行不会被反复阅读。
其他详细信息:缓冲的 reader 包装在输入流 Reader 中,我说的是 Java(Android)
String line = reader.readLine();
while (line != null) {
output.append(line);
line = reader.readLine();
}
当您读取文件时,有一个指针指向文件中的下一个读取位置。每次调用 readLine
时,指针都会继续移动,直到它看到 \r\n
或 \n
。然后指针停留在这里供您下次阅读。