-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScannerReadFile.java
33 lines (28 loc) · 967 Bytes
/
ScannerReadFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package RWFile;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Scanner;
public class ScannerReadFile {
public static void main(String[] args) throws IOException {
Scanner out = new Scanner(Paths.get("./chapter03/outfile.txt"), "UTF-8");
Scanner in = new Scanner(Paths.get("./chapter03/infile.txt"), "UTF-8");
System.out.println("Read the contents of the file outfile written by InputTest:\n");
try {
while (out.hasNext()) {
String s = out.nextLine();
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\nread the existing file infile:\n");
try {
while (in.hasNext()) {
String s = in.nextLine();
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}