Hi All,
Goal: I will have varying sizes of a comma delimited file that I need to import into my Java program and store in a 2D array. Please note the examples will be much larger than the ones listed below. They will be on the order of 10,000 x 10,000.
I have the code to import the comma delimited file, however I cannot seem to figure out a way to write the code to store it in a 2D array, and have the array size vary with the size of the file.
Examples of comma delimited file that needs to go into a 2D array:
#
Name,1,2,3,4,5
1,1,1,1,1,1
2,1,1,1,1,0
3,1,1,1,1,0
4,1,1,1,1,1
5,0,1,1,0,0
6,1,1,1,1,0
7,0,1,1,0,0
Name,1,2,3,4,5,6,7,8,9,10
1,1,1,1,1,1,1,1,1,1,1
2,1,1,1,1,0,1,1,1,1,1
3,1,1,1,1,0,0,0,1,1,1
4,1,1,1,1,1,1,0,1,1,1
5,0,1,1,0,0,1,0,1,0,0
6,1,1,1,1,0,1,1,1,0,1
7,0,1,1,0,0,1,1,0,0,1
8,1,1,1,0,0,1,1,0,1,1
9,1,1,1,1,0,1,1,1,1,1
10,1,1,1,1,0,1,0,1,1,1
11,1,0,0,0,0,0,0,1,0,0
12,0,1,1,0,0,1,1,1,0,0
13,0,1,0,0,0,1,1,0,0,0
14,0,1,1,0,0,1,0,1,0,0
15,1,1,1,0,0,0,0,1,0,1
My current code:
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException; public class CsvTest { public void readFile(String filePath ) { BufferedReader br = null; int intExp; try { br = new BufferedReader(new FileReader(filePath)); String line = null; } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } } } public static void main(String[] args) { CsvTest test = new CsvTest(); String path = "C:/comma_delim_test.csv"; test.readFile(path); } }