-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadFile.java
30 lines (28 loc) · 1.04 KB
/
ReadFile.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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.File;
///////////////////
// ReadFile: file reader used to read input and config file content
///////////////////
public class ReadFile extends OS {
public String lastReadFile;
//read - read the file and store it to the lastReadFile variable
public void read(String fileName) {
try {
File file = new File(fileName);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
stringBuffer.append("\n");
}
fileReader.close();
lastReadFile = stringBuffer.toString();
} catch (IOException e) {
console.error("The filename \"" + fileName + "\" does not exist or is corrupted");
}
}
}