Java Learning Notes (v)

Source: Internet
Author: User

Import Java.awt.BorderLayout;
Import Java.awt.Color;
Import Java.io.File;

Import Javax.swing.JComboBox;
Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
Import Javax.swing.JScrollPane;
Import Javax.swing.JTextArea;

public class FileUtils {
/**

    • lists the names of all files or directories in the specified folder (directory)
    • @param the folder (directory) specified by the Dir file type
    • @return
    • @throws illegalaccess Exception
      /
      public static String listdirectory (File dir) throws illegalaccessexception{
      // Determines whether the file and directory associated with DIR exists
      if (!dir.exists ()) {
      ///If it does not exist, throws an exception
      throw new Illegalaccessexception ("directory" + dir + "does not exist.) ");
      }
      //Determine if DIR is associated with a directory
      if (!dir.isdirectory ()) {
      throw new illegalaccessexception (dir + "not Directory");
      }
      /
      Gets the name of all files and folders under
    • current directory (dir) by invoking the list () method with the passed-in file Object dir.
      */
      string[] files = dir.list ();
      String m = "";
      for (String a:files) {
      m=m+a+ "\ n";}
      return m;
      }
      /**
    • @param args
      */
      public static void Main (string[] args) {
      //TODO auto-generated method stub
      JFrame frame=new JFrame ();
      JPanel main_panel =new JPanel (New BorderLayout ());
      Frame.setdefaultcloseoperation (jframe.exit_on_close);

String[] Itme = {". gif", ". bmp"};
JComboBox frm=new JComboBox (itme);
Frm.setenabled (TRUE);
Frm.seteditable (TRUE);
Frm.setmaximumrowcount (5);
Frm.setbounds (230,30,130,25);

Frame.setbounds (300,200,350,300);
Frame.setvisible (TRUE);
JTextArea main_text =new JTextArea ();
Main_text.setbackground (Color.White);
JScrollPane z=new JScrollPane ();
Z.setviewportview (Main_text);
Main_text.setenabled (FALSE);
Main_panel.add (Frm,borderlayout.north);
Main_panel.add (Z,borderlayout.center);
Frame.add (Main_panel);

try {
String str = fileutils.listdirectory (new File ("D:\FileUtils"));
Main_text.settext (str);
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}

Java Learning Notes (v)

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.