I have a .csv file and I understand how to read it in Java, my problem is I want to be able to put the values of what is inside the file into a string and then read the string so I can calculate these values.
Alice Jones,80,90,100,95,75,85,90,100,90,92 Bob
Manfred,98,89,87,89,9,98,7,89,98,78
Those are the values, now how could I add up all the integers next to each name and create an average? MY biggest problem was when I read the file it was in a While loop and then was able to print out the lines just as it looks above into the console but when I wanted to print the values outside of the While loop it said the string doesn't exist so therefore I can't calculate the values if there is nothing in it.
import java.io.*;
import java.util.*;
public class Grades {
public static void main(String args[]) throws IOException
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("filescores.csv");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
String line = strLine
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}