All files in the Java display directory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.