我想在我的 jar 文件中读取多个文件。但它不起作用。它只读取一个文件并停止。我真的不明白如何Inputstream
和Bufferedreader
工作。那部分代码是从另一篇文章中借来的。
for (int i = 0; i < numList; i++) { // numList is number of file I want to read
int fileNum = i + 1;
String fileaddress = "List" + fileNum + ".txt";
//All the files have name like "List1.txt", "List2.txt", etc
InputStream configStream = getClass().getResourceAsStream(fileaddress);
BufferedReader wordReader = new BufferedReader(new InputStreamReader(configStream, "UTF-8"));
//the following is to store values in the line in an String array
//add the array to an ArrayList called masterList
String[] line;
while((line = wordReader.readLine().split(": ")) != null){
masterList.add(line);
}