Reading the java files from the folder

前端 未结 2 447
谎友^
谎友^ 2021-01-29 01:06

I have developed an application that reads files from the folder chosen by the user. It displays how many lines of code are in each file. I want only Java files to be shown in t

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-29 01:20

    You need a FilenameFilter. This should work for you:

    FilenameFilter javaFileFilter= new FilenameFilter() {  
      @Override
      public boolean accept(File logDir, String name) {
        return name.endsWith(".java")
      }
    };
    

提交回复
热议问题