java操作文件相关
作者:
ljwheyxy | 来源:发表于
2019-11-05 19:24 被阅读0次 @Test
void testFile(){
System.out.println("根路径:"+System.getProperty("user.dir"));
File ff = new File("D:\\SmallWork\\周总报表\\source\\report4you");
File p = ff.getParentFile();
System.out.println(p.getName());
File file = new File(usersUrl); //获取其file对象
File[] fs = file.listFiles(); //遍历path下的文件和目录,放在File数组中
for(File f:fs){ //遍历File[]数组
if(!f.isDirectory()) //若非目录(即文件),则打印
System.out.println(f);
}
//List<String> stringList = Arrays.stream(name).filter(x -> !x.equals("赵强")).collect(toList());
List<File> fileList = Arrays.stream(fs).filter(x -> !x.isDirectory() && x.getName().substring(x.getName().lastIndexOf(".")+1).equals("csv")).collect(Collectors.toList());
// System.out.println(Arrays.toString(fileList));
for (File file1 : fileList) {
System.out.println(file1.getName());
}
}
本文标题:java操作文件相关
本文链接:https://www.haomeiwen.com/subject/slmebctx.html
网友评论