- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadFileExample.java
More file actions
Latest commit
29 lines (27 loc) · 844 Bytes
/
Copy pathReadFileExample.java
File metadata and controls
29 lines (27 loc) · 844 Bytes
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
packagecom.codinginterview;
importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileReader;
importjava.io.IOException;
importjava.util.Scanner;
publicclassReadFileExample {
publicstaticvoidmain(String[] args) {
System.out.println("Read a File Example");
}
privatestaticvoidreadFile(Stringpath) throwsIOException {
FileReaderfr = newFileReader(path);
BufferedReaderbr = newBufferedReader(fr);
Stringstr;
while((str = br.readLine()) != null ){
System.out.println(str);
}
br.close();
}
privatestaticvoidreadFile2(Stringpath) throwsIOException {
Filefile = newFile(path);
Scannersc = newScanner(file);
while(sc.hasNextLine()){
System.out.println(sc.nextLine());
}
}
}