public void test1() throws IOException { File file = new File("path"); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String str = null; while ((str = br.readLine()) != null) { System.err.println(str); } br.close(); fr.close(); } public void test2() throws IOException { Path path = Paths.get("text.txt"); List<String> fs = Files.readAllLines(path, StandardCharsets.UTF_8); for (String str : fs) { System.err.println(str); } } public void print(Object o) { String name = Thread.currentThread().getName(); System.err.println(name + ":" + o); }