使用readAllLines()方法读取文本文件
import java.io.IOException; import java.nio.charset.Charset;// 来 自 时代Java - nowjava.com import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; public class Main { public static void main(String[] args) { Path wiki_path = Paths.get("C:/folder1/wiki", "wiki.txt"); Charset charset = Charset.forName("ISO-8859-1"); try { List<String> lines = Files.readAllLines(wiki_path, charset); for (String line : lines) {