0

Can I read lines of file between two concrete positions (not begin & and) using BufferedReader in Java? I know how to read all lines from file by this method, but I need to read only one fragment of file.

5
  • 2
    1) Does the file contain records of fixed size? If so, consider using a RandomAccessFile. 2) If not, you can read through the file and start saving the text when you reach your begin position, and then stop reading and close the file once you've passed your end position. Commented Oct 9, 2013 at 23:23
  • You can pass over lines until you hit the section you want. Commented Oct 9, 2013 at 23:23
  • Can I write like this line = "SomeString" while (line = reader.readLine() != "endString") Commented Oct 9, 2013 at 23:26
  • No -- never use == or != to compare Strings ever. Use equals(...) or equalsIgnoreCase(...) instead. Commented Oct 9, 2013 at 23:41
  • while (!(currentLine = reader.readLine()).equals(endLine))?? Commented Oct 9, 2013 at 23:47

1 Answer 1

1

Yes you can

bufferedReader.skip(numberOfCharsToSkip);

See: http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#skip%28long%29

Sign up to request clarification or add additional context in comments.

1 Comment

@user2842269: by checking the line returned from the BufferedReader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.