I am trying to read data from a .txt
file, i need to be ignoring any line that starts with a //
or a blank line but i can't seem to get the delimiter to work correctly.
public void readVehicleData()
throws FileNotFoundException
{
FileDialog fileBox = new FileDialog(myFrame, "Open", FileDialog.LOAD);
fileBox.setVisible(true);
String filename = fileBox.getFile();
File vehicleData = new File(filename);
Scanner scanner = new Scanner(vehicleData).useDelimiter("\"(,\")?");
while( scanner.hasNext() )
{
String lineOfText = scanner.nextLine();
System.out.println(lineOfText);
}
scanner.close();
}
This is the .txt file i am trying to read:
// this is a comment, any lines that start with //
// (and blank lines) should be ignored
AA, TF-63403, MJ09TFE, Fiat
A, TF-61273, MJ09TFD, Fiat
A, TF-64810, NR59GHD, Ford
B , TF-68670,MA59DCS, Vauxhall
B, TF-61854, MJ09TFG, Fiat
B, TF-69215, PT09TAW, Peugeot
C, TF-67358, NR59GHM, Ford