Wednesday, 15 April 2015

java - Reading a file, getting the current position and reading backwards -



java - Reading a file, getting the current position and reading backwards -

i'm using bufferedreader class search occurrence in big file reading line line.

how can current position when occurrence found ? then, how can read in reverse file starting @ position ?

i searched on net consistent solution haven't found.

public static void main(string[] args) throws exception { filereader fr = new filereader("sample.txt"); bufferedreader reader = new bufferedreader(fr); string line = ""; arraylist<string> linee = new arraylist<string>(); while ((line = reader.readline()) != null) { if (line.equals("bb")) break; linee.add(line); } reader.close(); (int = linee.size() - 1; >= 0; i--) system.out.println(linee.get(i)); }

java file

No comments:

Post a Comment