+-

参见英文答案 > Read text file into an array 5个
嗨我想读取带有N行的txt文件,结果将其放入字符串数组中.
嗨我想读取带有N行的txt文件,结果将其放入字符串数组中.
最佳答案
使用
java.util.Scanner和
java.util.List.
Scanner sc = new Scanner(new File(filename));
List<String> lines = new ArrayList<String>();
while (sc.hasNextLine()) {
lines.add(sc.nextLine());
}
String[] arr = lines.toArray(new String[0]);
点击查看更多相关文章
转载注明原文:java:如何将txt文件读取到字符串数组 - 乐贴网