Reputation: 25
The user can select a file to be scanned, however none of the file's contents are printed at run-time, any help?
public void readVehicleData(){
FileDialog fileBox = new FileDialog(mainWindow,"Open", FileDialog.LOAD);
fileBox.setVisible(true);
fileBox.setDirectory(".");
String dataFile = fileBox.getFile();
Scanner scanner = new Scanner(dataFile);
while( scanner.hasNext() )
{
String lineOfInput = scanner.nextLine();
System.out.println(lineOfInput);
}
scanner.close();
}
Upvotes: 1
Views: 85
Reputation: 159784
Use the constructor that accepts a File rather than a String as its InputStream
source
Scanner scanner = new Scanner(new File(dataFile));
Upvotes: 7