vendredi 27 février 2015

java filereader splitting strings



So Im stuck on a homework assignment, and would only like a little bit of assistance I have 3 text files with multiple student names and their grades in the format:


Student Name


Test 1: 93




Student Name


Test 1: 99




I need to figure out a way to split the line where the grade is and skip the ------- that splits the students and their grades up. I would then need to parse the test grade into a variable so i could do calculations with it.



public void openFile() throws IOException {
//opens text file
try {
FileReader inputFile = new FileReader("C:\\Users\\Chris\\IdeaProjects\\workshop3\\src\\filereader\\file1.txt");
//delimiter from scanner object skips characters passed as parameters
kb = new Scanner(inputFile).useDelimiter("\n");
while(kb.hasNext()){
line = kb.next();
System.out.println(line);
}


} catch (IOException e) {
e.printStackTrace();
}



Aucun commentaire:

Enregistrer un commentaire