作者:lkiouy_107 | 来源:互联网 | 2023-09-25 13:16
您不需要2D
数组来存储文件内容,可以使用String []数组列表,例如:
public List readData() throws IOException {
int count = 0;
String file = "bank-Detail.txt";
List cOntent= new ArrayList<>();
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
String line = "";
while ((line = br.readLine()) != null) {
content.add(line.split(","));
}
} catch (FileNotFoundException e) {
//Some error logging
}
return content;
}
同样,在您的情况下,最好在list
本地声明并从中返回它,method
而不是将元素添加到共享list
(“ bank”)中。