Can BufferedReader(Java)可以在不移动指针的情况下读取下一行吗? [英] Can BufferedReader (Java) read next line without moving the pointer?
本文介绍了Can BufferedReader(Java)可以在不移动指针的情况下读取下一行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在不移动指针的情况下阅读下一行,这可能吗?
I am trying to read next next line without moving the pointer, is that possible?
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
while ((readString = buf.readLine()) != null) {
}
虽然我会想要逐行阅读,但我需要写下当前行的下一行。
the While will read line by line as i want, but i need to write the next line of the current line.
这是可能的?
我的文件包含Http请求数据,第一行是GET请求,第二行是
主机名,我需要拉在GET之前将主机连接在一起。
主机/ + GET网址,
my file contain Http request data, the first line is the GET request,
in the second line the Host name, i need to pull out the Host before the GET to be able to connect it together.
Host/+the GET url,
GET /logos/2011/family10-hp.jpg HTTP/1.1
Host: www.google.com
Accept-Encoding: gzip
谢谢。
推荐答案
您可以使用 mark()
和 reset()
标记流中的一个点然后返回它。示例:
You can use mark()
and reset()
to mark a spot in the stream and then return to it. Example:
int BUFFER_SIZE = 1000;
buf.mark(BUFFER_SIZE);
buf.readLine(); // returns the GET
buf.readLine(); // returns the Host header
buf.reset(); // rewinds the stream back to the mark
buf.readLine(); // returns the GET again
这篇关于Can BufferedReader(Java)可以在不移动指针的情况下读取下一行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文