15.6 Opening Files with JFileChooser

Class JFileChooser displays a dialog that enables the user to easily select files or directories. To demonstrate JFileChooser, we enhance the example in Section 15.3, as shown in Figs. 15.1215.13. The example now contains a graphical user interface, but still displays the same data as before. The constructor calls method analyzePath in line 24. This method then calls method getFileOrDirectoryPath in line 31 to retrieve a Path object representing the selected file or directory.

 1   // Fig. 15.12: JFileChooserDemo.java 2   // Demonstrating JFileChooser. 3   import java.io.IOException; 4   import java.nio.file.DirectoryStream; 5   import java.nio.file.Files; 6   import java.nio.file.Path; ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.