-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRead.java
More file actions
46 lines (36 loc) · 1.24 KB
/
Read.java
File metadata and controls
46 lines (36 loc) · 1.24 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
package base;
import java.io.*;
public class Read {
public static String read(String hi) {
// The name of the file to open.
String fileName = "textE.txt";
String text;
// This will reference one line at a time
try {
// FileReader reads text files in the default encoding.
FileReader fileReader =
new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
String values = bufferedReader.readLine();
hi = values;
// Always close files.
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
// Or we could just do this:
// ex.printStackTrace();
} finally {
return hi;
}
}
}