### Question:
FileUtil { public final static List<String> lines(File file) { List<String> list = new ArrayList<>(); try ( BufferedReader reader = new BufferedReader(new FileReader(file)) ) { String line; while ((line = reader.readLine()) != null) { list.add(line); } } catch (IOException e) { e.printStackTrace(); } return list; }  static String fileMD5(File file); final static int countLines(File file); final static List<String> lines(File file); final static List<String> lines(File file, String encoding); final static List<String> lines(File file, int lines); final static List<String> lines(File file, int lines, String encoding); final static boolean appendLine(File file, String str); final static boolean appendLine(File file, String str, String encoding); final static boolean write(File file, String str); final static boolean writeAppend(File file, String str); final static boolean write(File file, String str, String encoding); final static boolean writeAppend(File file, String str, String encoding); final static boolean cleanFile(File file); final static String mimeType(String file); final static String fileType(File file); final static Date modifyTime(File file); final static boolean copy(String resourcePath, String targetPath); final static boolean copy(File file, String targetFile); final static boolean createPaths(String paths); final static boolean createFiles(String filePath); final static boolean deleteFile(File file); final static boolean deleteDir(File file); final static boolean deleteBigFile(File file); final static void copyDir(String filePath, String targetPath); final static void copyDir(File filePath, String targetPath); final static List<File> listFile(String path); final static List<File> listFile(String path, boolean child); final static List<File> listFile(File path); final static List<File> listFile(File path, boolean child); final static List<File> listFileAll(File path); final static List<File> listFileFilter(File path, FilenameFilter filter); final static List<File> listFileFilter(File dirPath, final String postfixs); final static List<File> searchFile(File dirPath, String fileName); final static List<File> searchFileReg(File dirPath, String reg); final static String suffix(File file); static MessageDigest MD5; }### Answer:
@Test public void testLines() { System.out.println("=====按List讲文件全部读入到List中======"); System.out.println("全英文文件测试"); String efile = path + "/text/English.txt"; List<String> lines = FileUtil.lines(new File(efile)); System.out.println(lines); System.out.println("读取文件的前3行"); lines = FileUtil.lines(new File(efile), 3); System.out.println(lines); System.out.println("GBK文件测试"); String gbkfile = path + "/text/GBK.txt"; List<String> gbklines = FileUtil.lines(new File(gbkfile)); System.out.println(gbklines); gbklines = FileUtil.lines(new File(gbkfile), "GBK"); System.out.println(gbklines); System.out.println("读取文件的前3行"); lines = FileUtil.lines(new File(gbkfile), 3, "GBK"); System.out.println(lines); System.out.println("UTF8文件测试"); String utf8file = path + "/text/UTF8.txt"; List<String> utf8lines = FileUtil.lines(new File(utf8file)); System.out.println(utf8lines); utf8lines = FileUtil.lines(new File(utf8file), Opslab.UTF_8); System.out.println(utf8lines); System.out.println("读取文件的前3行"); lines = FileUtil.lines(new File(utf8file), 3, Opslab.UTF_8); System.out.println(lines); }