Aaron Patterson
Aaron Patterson

Reputation: 25

File read but won't print contents

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

Answers (1)

Reimeus
Reimeus

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

Related Questions