Reading the java files from the folder

前端 未结 2 412
谎友^
谎友^ 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")
      }
    };
    
    0 讨论(0)
  • 2021-01-29 01:37

    You should look upon Filtering the list of Files in JFileChooser.

    It has an example of ImageFilter.java which shows only image files in file chooser.

    0 讨论(0)
提交回复
热议问题