Goal: I'm trying to process a .txt file into a String[]
. File must be read per line, spliced on "," and stored in array. Each element (6 elements per line) must have it's own index in the array and must individually be accessible.
File (partially):
210,20140101, 1, 60, 67, -1 210,20140101, 2, 60, 65, 0 210,20140101, 3, 60, 58, 0 210,20140101, 4, 60, 56, 0 210,20140101, 5, 60, 49, 0 210,20140101, 6, 60, 53, 0 210,20140101, 7, 60, 55, 0 210,20140101, 8, 70, 59, 0
Code so far:
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
for (String line; (line = br.readLine()) != null;) {
counter++;
if (counter > 51) {
line = br.readLine();
line = line.trim();
list = Arrays.asList(line.split("\\s*,\\s*"));
}
}
}
for (String x : list) {
System.out.println(x);
}
Output so far:
391
20141231
24
20
1
0
Which is exactly what I need, but for every line (stored in a String array). Only the last line of the file is stored in the array using the code above.
I've already tried the suggestions here and here. Any suggestions or hints?