@Test public void testListFile() { System.out.println("罗列指定目录下的所有文件"); String path = System.getProperty("user.dir") + "/Junit/Resource/temp/"; List<File> files = FileUtil.listFile(new File(path)); PrintUtil.print(files); List<File> files1 = FileUtil.listFile(path); PrintUtil.print(files1); }
@Test public void testSearchFile() { System.out.println("在指定的目录下搜索指定的文件"); String path = System.getProperty("user.dir") + "/Junit/Resource/"; List<File> files = FileUtil.searchFile(new File(path), "GBK.txt"); PrintUtil.print(files); }
@Test public void testListFileFilter() { System.out.println("罗列指定目录下的特定后缀的文件"); String path = System.getProperty("user.dir") + "/Junit/Resource/"; List<File> files = FileUtil.listFileFilter(new File(path), ".txt"); PrintUtil.print(files); }
@Test public void testSearchReg() { System.out.println("在指定的目录下搜索符合某正则的文件"); // 匹配字母和数字组成的exe文件 String reg = "\\w{1,}\\.png$"; String path = System.getProperty("user.dir") + "/Junit/Resource/"; List<File> files = FileUtil.searchFileReg(new File(path), reg); PrintUtil.print(files); }
@Test public void testLines() { System.out.println("=====按List讲文件全部读入到List中======"); PrintUtil.print("全英文文件测试"); String efile = System.getProperty("user.dir") + "/Junit/Resource/English.txt"; List<String> lines = FileUtil.lines(new File(efile)); PrintUtil.print(lines); PrintUtil.print("读取文件的前3行"); lines = FileUtil.lines(new File(efile), 3); PrintUtil.print(lines); PrintUtil.print("GBK文件测试"); String gbkfile = System.getProperty("user.dir") + "/Junit/Resource/GBK.txt"; List<String> gbklines = FileUtil.lines(new File(gbkfile)); PrintUtil.print(gbklines); gbklines = FileUtil.lines(new File(gbkfile), "GBK"); PrintUtil.print(gbklines); PrintUtil.print("读取文件的前3行"); lines = FileUtil.lines(new File(gbkfile), 3, "GBK"); PrintUtil.print(lines); PrintUtil.print("UTF8文件测试"); String utf8file = System.getProperty("user.dir") + "/Junit/Resource/UTF8.txt"; List<String> utf8lines = FileUtil.lines(new File(utf8file)); PrintUtil.print(utf8lines); utf8lines = FileUtil.lines(new File(utf8file), "UTF-8"); PrintUtil.print(utf8lines); PrintUtil.print("读取文件的前3行"); lines = FileUtil.lines(new File(utf8file), 3, "UTF-8"); PrintUtil.print(lines); }