Reputation: 16669
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?
Upvotes: 3
Views: 1551
Reputation: 18588
You can use read(char[] buffer,int offet,int length)
for this purpose.
Upvotes: 1
Reputation: 21449
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 use BufferedReader.skip(long n)
to skip the rest.
OR You can read your line and then truncate it to the length you are expecting.
String line = bufferedReader.readLine();
String truncatedLine = line.substring(0, expectedLength);
Upvotes: 0
Reputation: 3738
Is this what you mean?
public int read(char[] buf, int offset, int count)
where:
buf - The array into which the chars read should be stored, offset - The offset into the array to start storing chars, count - The requested number of chars to read
Upvotes: 1