应用JFileChooser获得选择的文件路径
使用JFileChooser获得选择的文件路径private JFileChooser fcnew JFileChooser()fc.setFileSelectionMod
使用JFileChooser获得选择的文件路径
private JFileChooser fc=new JFileChooser();fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//只能选择目录String path=null;File f=null;try{ flag=fc.showOpenDialog(null); } catch(HeadlessException head){ System.out.println("Open File Dialog ERROR!"); } if(flag==JFileChooser.APPROVE_OPTION){ //获得该文件 f=fc.getSelectedFile(); path=f.getPath(); } //以上获得选择的文件夹//若要判断其中是否还有其他目录,可以这样做boolean hasSubDir=false;File dir=new File(path);//获得改目录下的文件的文件名,如果没有的话,filesName.length()=0String filesName=dir.list();for(int i=0;i<filesName.length();i++){ File temp=new File(path+"/"+filesName[i]); if(temp.isDirectory()){ hasSubDir=true; break; }}