|
a |
|
b/util/FileToList.java |
|
|
1 |
package util; |
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader; |
|
|
4 |
import java.io.File; |
|
|
5 |
import java.io.FileReader; |
|
|
6 |
import java.io.IOException; |
|
|
7 |
import java.util.ArrayList; |
|
|
8 |
import java.util.List; |
|
|
9 |
|
|
|
10 |
/** |
|
|
11 |
* Utility class to read a txt file into a List |
|
|
12 |
* @author zhengc |
|
|
13 |
* |
|
|
14 |
*/ |
|
|
15 |
public class FileToList { |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* Creates a List from a txt file |
|
|
19 |
* @param filename file that contains items |
|
|
20 |
* @return a List |
|
|
21 |
* @throws IOException |
|
|
22 |
*/ |
|
|
23 |
public static List<String> createListFromfile(String filename) throws IOException { |
|
|
24 |
List<String> genelist = new ArrayList<>(); |
|
|
25 |
BufferedReader br = new BufferedReader(new FileReader(new File(filename))); |
|
|
26 |
String gene = null; |
|
|
27 |
while ((gene = br.readLine()) != null) { |
|
|
28 |
genelist.add(gene); |
|
|
29 |
} |
|
|
30 |
br.close(); |
|
|
31 |
return genelist; |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
} |