-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFileReader.java
More file actions
36 lines (32 loc) · 817 Bytes
/
TextFileReader.java
File metadata and controls
36 lines (32 loc) · 817 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
30
31
32
33
34
35
36
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TextFileReader {
public String read(String filename){
return read(new File(filename));
}
public String read(File file){
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String output = "";
String line;
br.mark(1);
if (br.read() != 0xFEFF)
br.reset();
while((line = br.readLine()) != null){
output += line + "\n";
}
return output;
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}