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 folder (directory) specified by dir file type
* @return
* @throws illegalaccessexception
*/
public static String ListDirectory (File dir) throws illegalaccessexception{
Determine if the files and directories associated with dir exist
if (!dir.exists ()) {
Throws an exception if it does not exist
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");
}
/* With the passed in file object dir calls the list () method to obtain
* The name of all files and folders under the current directory (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 ());//panel
Frame.setdefaultcloseoperation (Jframe.exit_on_close);
Frame.setlayout (NULL);
Set combo box
String[] Itme = {". png", "ico"};
JComboBox frm=new JComboBox (itme);
Frm.setenabled (TRUE);
Frm.seteditable (TRUE);
Frm.setmaximumrowcount (5);
Frm.setbounds (230,30,130,25);
Frame.setbounds (400,200,350,400);
Frame.setvisible (TRUE);
JTextArea main_text =new JTextArea ();
Main_text.setbackground (Color.Black);
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:\\$_outdir\\skin"));
Main_text.settext (str);
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
Fifth time Java Job