Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Java I/O part I Using scanner 8-Nov-18.

Similar presentations


Presentation on theme: "Simple Java I/O part I Using scanner 8-Nov-18."— Presentation transcript:

1 Simple Java I/O part I Using scanner 8-Nov-18

2 Scanner You can use the Scanner class to read from a file just like you read from the console. File file = new File(“Random"); That is very similar to your Python file code. Scanner scanner = new Scanner(file);

3 Reading firstLine = scanner.nextLine();
for (int i = 0; i < N; i++) { String information = scanner.nextLine(); }

4 Catching exceptions Java forces you to catch some file related exceptions try { File file = new File(“blabla.txt”); Scanner scanner = new Scanner(file); } catch (FileNotFoundException e) { e.printStackTrace(); In the JavaExperiments folder on Dropbox, look at FileRead.java


Download ppt "Simple Java I/O part I Using scanner 8-Nov-18."

Similar presentations


Ads by Google