I have a text file that looks roughly like this:
type, distance, length, other,
A, 62, 17, abc,
A, 12, 4,,
A, 6, 90,,
A, 46, 53,,
etc.
Everything is separated by commas, but sometimes there is a blank. I need to be able to read this data into an array using a scanner (not bufferedreader) and be able to account for the blanks somehow, as well as split by commas. Later I will need to be able to calculate things with the data in each column. How do I get this data into the array?
This is what I have so far: (java)
import java.util.Scanner;
import java.io.*;
public class RunnerAnalysis {
public static void main(String[] args) throws IOException {
Scanner keyboard = new Scanner(System.in);
System.out.print("File: ");
String filename = keyboard.nextLine();
File file = new File(filename);
Scanner inputFile = new Scanner(file);
inputFile.nextLine();
String line = inputFile.nextLine();
while(inputFile.hasNext())
{
String[] array = line.split(",");
}
}
}