我有一個Java method
(下圖)來檢查一個text file
爲string
值然後加上然後到list
:確保文本文件中的空行沒有添加到列表中?
public List<String> iterateTextFile(String filePath) {
List<String> lines = new ArrayList<String>();
try {
lines = Files.readLines(new File(filePath), Charset.forName("utf-8"));
}catch(IOException e){
e.printStackTrace();
}
return lines;
}
然而,這種方法將增加空行例如爲:""
到ArrayList
爲好。我不想要這個?
如何添加驗證以使其不會發生?