Java Fifth time job

Source: Internet
Author: User


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

Import Javax.swing.JFrame;
Import javax.swing.JList;
Import Javax.swing.JMenu;
Import Javax.swing.JMenuBar;

public class FileUtils {
/**
* Lists all files in the specified folder (directory) or the name of the directory
* @param dir file type indicates the specified folder (directory)
* @return
* @throws illegalaccessexception
*/
public static string[] ListDirectory (File dir) throws illegalaccessexception{
Determine if the file or directory to which dir is associated exists
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 IllegalArgumentException (dir+ "is not a directory");
}
Call the list () method with the file object passed in to get the names of all the files and folders under the current directory (dir) (excluding directories)
String[] Files =dir.list ();
for (String s:files)
System.out.println (dir+ "\ \" +s);
file[] FileNames = Dir.listfiles ();
for (File f:filenames) {
Determines whether the file object is a document, is the file output name
if (F.isfile ()) {
System.out.println (f);
return files;
}


/**
* @param args
* @throws illegalaccessexception
*/
public static void Main (string[] args) throws Illegalaccessexception {
TODO auto-generated Method Stub
Final JFrame frm = new JFrame ("");
Frm.setdefaultcloseoperation (Jframe.exit_on_close);

JList JList = new JList (Fileutils.listdirectory (New File ("C:\\users\\pc\\desktop\\java job 5\\soundplayer"));

Frm.add (jList);
Jlist.setbackground (Color.Black);
Jlist.setforeground (Color.Blue);

JMenuBar mbar = new JMenuBar ();
Frm.setjmenubar (mbar);
JMenu m1 = new JMenu ("Files");
JMenu m2 = new JMenu ("list");
Mbar.add (M1);
Mbar.add (m2);
Frm.setbounds (400, 200, 200, 300);
Frm.setvisible (TRUE);


try {
Fileutils.listdirectory (New File ("C:\\users\\pc\\desktop\\java job 5\\soundplayer"));
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}}

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.