Well, you could use my method but instead of making it a huge string, save each string to a list:
In your class, define a new variable:
Then, use this code:
To get something from the list, use this:
1 | ArrayList<String> out = new ArrayList<String>(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public void load() throws Exception { BufferedReader in = new BufferedReader( new FileReader( "a.txt" )); int num = 0 ; //File Line Count String t = "" ; int start = Integer.parseInt(in.readLine()); //First number in file while ((t = in.readLine()) != null ) //Ensures that there is something to read { num++; //Increase num by 1 //do stuff with the string 't' which has each line of file every time out.add(t); //Adds the contents of the line to the list } in.close(); } |
1 | String thirdLine = out.get( 2 ); //subtract one from wanted line. |