Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.