java JFileChooser File Size Filter

前端 未结 2 1761
后悔当初
后悔当初 2021-01-16 12:53

I know I can make a filter by file type, but is it possible to filter by file size?

For example a JFileChooser to show only pictures within 3 MegaBytes.

2条回答
  •  别那么骄傲
    2021-01-16 13:18

    Create a sub-class of FileFilter. In the accept method, decide if the file is too large or not.

    public boolean accept(File f) {
        if(f.length() > maxSize) return false;
        return true;
    }
    

    Then apply the filter to your File Chooser

提交回复
热议问题