Package Gao.org;import Java.awt.headlessexception;import Java.io.file;import Javax.swing.jfilechooser;public class ReadFile1 {public static void main (String []args) {JFileChooser fc=new jfilechooser (); Fc.setfileselectionmode ( JFILECHOOSER.DIRECTORIES_ONLY);//Can only select folder string Path=null; File f=null;int flag = 0;try{flag=fc.showopendialog (null); } catch (Headlessexception head) {System.out.println ("Open File Dialog error!"); } if (flag==jfilechooser.approve_option) {//Get the file F=fc.getselectedfile (); Path=f.getpath (); }//above to get the selected folder//To infer if there are any other folders, be able to do so Boolean hassubdir=false; File dir=new (path);//Get the filename of the file under the Change folder, if not, Filesname.length () =0string[] filesname=dir.list (); for (int i=0;i <filesname.length;i++) {file Temp=new file (path+ "/" +filesname[i]); System.out.println (Filesname[i]); if (Temp.isdirectory ()) {hassubdir=true; Break }}}} Here is a simple demo display folder under the file
All files in the Java display directory