Hello,
I'm trying to import a csv file into a 2D array and then find the average of each column. The csv file contains 3 columns each with 994 rows and consists entirely of doubles. I am very new to Java programming but have managed to write some code to read the file and populate an array. The problem I'm having is the data all seems to be in one column instead of three? I've done alot of research and can't figure out what is missing. My code so far is below. Any help would be greatly appreciated!
Thank you
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; public class csvimport { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub double [][] data = new double [994][2]; String line = null; int row = 0; int col = 0; File file = new File("data.csv"); BufferedReader bufRdr = new BufferedReader(new FileReader(file)); //read each line of text file while((line = bufRdr.readLine()) != null && row < 994) { StringTokenizer st = new StringTokenizer(line,","); while (st.hasMoreTokens()) st.nextToken(); col++; { col=0; } { String[] values = line.split(","); for (String str : values) { double str_double = Double.parseDouble(str); data[row][col]=str_double; System.out.println(str_double); } } } } }