java操作文件相关

2019-11-05  本文已影响0人  ljwheyxy
 @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());
        }
    }
上一篇下一篇

猜你喜欢

热点阅读