-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextFileReader.java
More file actions
41 lines (37 loc) · 938 Bytes
/
TextFileReader.java
File metadata and controls
41 lines (37 loc) · 938 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
37
38
39
40
41
package TextFileManager;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TextFileReader {
public List<String> readFileToList(String fileName){
BufferedReader br = null;
List<String> strArray = new ArrayList<String>();
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(true) {
String line =null;
try {
line = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (line == null){
break;
}
strArray.add(line);
}
return strArray;
}
public String readFile(String fileName) {
String fileContent = String.join("\n", this.readFileToList(fileName));
return fileContent;
}
}