How can i write a string to a file so that the last string that was in the file stays there and the new string goes to a new line?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | String line; int [] score = new int [ /* amount of scores in file */ ]; // all the code here is good besides for this line (I think) BufferedReader br; try { int loopCount = 0 ; br = new BufferedReader( new FileReader( "score.txt" )); while ((line = br.readLine()) != null ) { score[loopCount] = Integer.valueOf(line); loopCount++; } br.close(); } catch (IOException ex) { System.out.println(ex.getMessage()); } |
1 | "Billy Bob:2550::Bobby Sue:2280::" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // count the records String temp = line; int recordCount = 0 ; while (! "" .equals(temp)) { temp = temp.substring(temp.indexOf( "::" )+ 2 ); recordCount++; } // parsing the data Object[][] data = new Object[recordCount][ 2 ]; for ( int i= 0 ; i<recordCount; i++) { int recLen = line.indexOf( "::" ); String record = line.substring( 0 , recLen); line = line.substring(recLen+ 2 ); int nameLen = record.indexOf( ":" ); data[i][ 0 ] = record.substring( 0 , nameLen); data[i][ 1 ] = Integer.valueOf(record.substring(namLen+ 1 )); } |
1 2 | String name = (String)data[n][ 0 ]; int score = (Integer)data[n][ 1 ]; |
1 2 | String name = (String)data[n][ 0 ]; int score = (Integer)data[n][ 1 ]; |
1 | String record = line.substring( 0 , recLen); |
1 2 | String name = (String)data[n][ 0 ]; int score = (Integer)data[n][ 1 ]; |
1 | String record = line.substring( 0 , recLen); |