I need to read the text from a .dat file that goes as such:
4
Mary 13.99
Ruth 22.04
Anne 12.39
Talor 18.34
I used a buffered reader that looks like this:
public class Tester{
public static void main(String [] args){
BufferedReader reader = null;
try {
File file = new File("C:\\Users\\hoguetm\\workspace\\practiceproblems\\beautiful.dat");
reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
//System.out.println(line);
//split will go here
String[] str1Array = line.split(" ");
System.out.println(str1Array[0]);
//works
/*
for (String retval: line.split(" ")){
System.out.println(retval);
}
*/
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
i need to add the numbers at the end of the lines except the 4 and print the sum out, but when i change [0] to [1] it says out of range. please help