[61e40d]: / util / FileToList.java

Download this file

35 lines (30 with data), 750 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
package util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Utility class to read a txt file into a List
* @author zhengc
*
*/
public class FileToList {
/**
* Creates a List from a txt file
* @param filename file that contains items
* @return a List
* @throws IOException
*/
public static List<String> createListFromfile(String filename) throws IOException {
List<String> genelist = new ArrayList<>();
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
String gene = null;
while ((gene = br.readLine()) != null) {
genelist.add(gene);
}
br.close();
return genelist;
}
}