Java Fifth time job

Source: Internet
Author: User

Package Liebiao;

Import Java.io.File;

Import Javax.swing.JFrame;
Import javax.swing.JList;
public class Liebiao extends jframe{

private static final File dir = null;
private static Object String;
/**
* @param args
* @throws illegalaccessexception
*/
public static string[] ListDirectory (File dir) throws illegalaccessexception{
To determine if the file object Dir exists, use the exists () method of the File class
if (!dir.exists ()) {
Throws an exception if it does not exist
throw new Illegalaccessexception ("directory" + dir + "does not exist.) ");
}
To determine if dir is a directory, use the Isdirectory () method of the File class
if (!dir.isdirectory ()) {
throw new IllegalArgumentException (dir + "not Directory");
}

Obtain the files and subdirectories under dir of the specified directory and output (1.list (); 2.listFiles ())

Use the list () method to implement
string[] FileNames = Dir.list ();
for (String s:filenames)
System.out.println (s);

Use the Listfiles () method to implement all file names that are listed in the directory only
file[] files = dir.listfiles ();
return fileNames;
}


public static void Main (string[] args) {
TODO auto-generated Method Stub
JFrame frm = new JFrame ();
Frm.setbounds (500,200,300,500);

Frm.setvisible (TRUE);
try {
Liebiao.listdirectory (New File ("F:"));
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}

Package Liebiao;

Import javax.swing.*;
Import Javax.swing.border.CompoundBorder;
Import Javax.swing.border.EmptyBorder;
Import Java.awt.BorderLayout;
Import Java.awt.Color;
Import Java.awt.Font;
Import Java.awt.Scrollbar;
Import java.awt.event.*;
Import Java.io.File;
Import Java.io.File;
Import javax.swing.JList;


public class Fileutilsframe {

private static JLabel Infolabel;
private static JSlider slider;
private static JList list;
private static Listmodel FileName;


public static void Main (string[] args) throws Exception {
TODO auto-generated Method Stub

Final JFrame frm = new JFrame ("");
Frm.setdefaultcloseoperation (Jframe.exit_on_close);

jlist<string> JList = new Jlist<> (Liebiao.listdirectory (New File ("F:"));

Frm.add (jList);
JLabel Northlabel = new JLabel ("Files list");
Frm.add (Northlabel,borderlayout.north);




Frm.setbounds (400, 200, 200, 500);
Frm.setvisible (TRUE);

}
}

Java Fifth time job

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.