Lists all file names under the directory---Listfiles.java

Source: Internet
Author: User
Tags tostring
File name/*
* Created on 2004-12-9
* I haven't found a common software that has this feature, so I wrote this class
* You can list files in the CD in TXT file, easy to find in the future, or print out.
* Do not need to find a disc in a CD-ROM to find a CD, slow and loss of optical drive.
* Of course, you can also select a directory to record all the file names under the directory.
*/

/**
* @author Shi Weifeng
* The Listfiles class can write all the file names in the directory to the text file you specify.
*/
Import java.io.*;
public class Listfiles {
private static String listfilestr= "";
public static void Main (string[] args) {
Try
{
File Savefile=new file (args[1]);
FileWriter fw=new FileWriter (savefile);
Listfiles lf=new listfiles ();
Lf.listfile (Args[0]);
Fw.write (LISTFILESTR);
Fw.close ();
}
catch (arrayindexoutofboundsexception ea)
{
Parameter hints
System.out.println ("Usage:listfiles <source dir> <target file>");

}
catch (IOException E)
{
System.out.println ("IO error!\r\n" +e.tostring ());
}

}
public void ListFile (String rp)
{

File File=new file (RP);
File List[]=file.listfiles ();
for (int i=0;i<list.length;i++)
{
Try
{
if (List[i].isdirectory ())
{
New Listfiles (). ListFile (List[i].tostring ());
}
Else
{
Listfilestr+=list[i].getabsolutepath () + "\ r \ n";
System.out.println (List[i].getabsolutepath ());
}
}
catch (Exception ex)
{
listfilestr+= "Access deny:" +list[i].getabsolutepath () + "\ r \ n";
SYSTEM.OUT.PRINTLN ("Access Deny:" +list[i].getabsolutepath ());
}
}
}

}



Related Article

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.