forked from KengoTODA/java-diff-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
47 lines (43 loc) · 1.13 KB
/
Copy pathExample.java
File metadata and controls
47 lines (43 loc) · 1.13 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
47
package diffutils.examples;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
public abstract class Example {
/** File separator. */
protected static final String FS = File.separator;
/** The base resource path. */
protected static String BASE_PATH = "src" + FS + "test" + FS + "resources";
/**
* Tries to read the file and split it into a list of lines.
*
* @param filename
* The filename as path.
* @return A list of lines.
*/
public static List<String> fileToLines(String filename) {
List<String> lines = new LinkedList<String>();
String line = "";
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(filename));
while ((line = in.readLine()) != null) {
lines.add(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore ... any errors should already have been
// reported via an IOException from the final flush.
}
}
}
return lines;
}
}