Tutorialspoint

1 Answer
Arjun Thakur

Set the following to FALSE to enable the display of hidden files −

JFileChooser file = new JFileChooser();
file.setFileHidingEnabled(false);

The following is an example to enable the display of hidden files in a JFileChooser −

Example

package my;
import javax.swing.JFileChooser;
public class SwingDemo {
   public static void main(String[] args) {
      JFileChooser file = new JFileChooser();
      file.setMultiSelectionEnabled(false);
      file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
      file.setFileHidingEnabled(false);
      int res = file.showOpenDialog(null);
      if (res == JFileChooser.APPROVE_OPTION) {
         java.io.File f = file.getSelectedFile();
         System.err.println(f.getPath());
      }
   }
}

The output is as follows. This displays the hidden files and directories.

Above, the “amit.txt” abd “desktop.ini” were hidden files and are now visible.

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.