I have had experience with tokenizers, but not sure how to add it to the following piece of code... can anyone help?
The code gives the following output...Code:import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException; public class ReadTextFileExample { public void getScore() { File file = new File("scores.txt"); StringBuffer contents = new StringBuffer(); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String text = null; //repeat ten times. while ((text = reader.readLine()) != null) { contents.append(text).append(System.getProperty("line.separator")); } } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } // show file contents here System.out.println(contents.toString()); } }
the reason i need to use tokenizers, is to separate the names, and scores... thanks...Code:John 5000 Lewis 3000 Eamon 2000 Leam 1000




Reply With Quote