有没有办法告诉 java BufferedReader 读取到某个点
我正在使用 Java BufferedReader 并使用 bufferedReader.readline() 逐行读取文件。
有没有一种方法可以让我知道该行有这么多文本,并且不要阅读超出的文本。
换句话说,是否已经存在可以看到行内容大小然后开始阅读的东西。那么它会读取到提供的大小吗?
I am using Java BufferedReader and reading file line by line using bufferedReader.readline().
Is there a way by which I can tell that the line has this much text and Don't read it beyond that.
In other words is there already existing something which sees the line content size and then start reading. Then it would be reading upto the size which is provided?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是 这个< /a> 你的意思是?
其中:
Is this what you mean?
where:
您可以使用 read(char[] buffer,int offset,int length) 来实现此目的。
You can use
read(char[] buffer,int offet,int length)
for this purpose.如果您知道一行的大小,则可以使用 BufferedReader.read(char[] cbuf, int off, int len) 读取您想要的内容并使用 BufferedReader.skip(long n ) 跳过其余部分。
或
您可以阅读您的行,然后将其截断为您期望的长度。
If you know the size of a line than you can use
BufferedReader.read(char[] cbuf, int off, int len)
to read what you want and useBufferedReader.skip(long n)
to skip the rest.OR
You can read your line and then truncate it to the length you are expecting.