JSP display all files and subdirectory code under the directory

Source: Internet
Author: User

JSP tutorial shows all files and subdirectory code under the directory

public static void GetFiles (list<file> filelist, string path, string filesuffix) {
File File = new file (path);
file[] files = file.listfiles ();
if (files = null) {
Return
} else {
for (int i = 0; i < files.length; i++) {
Determine if it is a folder
if (Files[i].isdirectory ()) {
Recursive call GetFiles method to get all the files
GetFiles (FileList, Getavailablepath (files[i)), filesuffix);
else if (Files[i].getname (). LastIndexOf (Filesuffix)!=-1) {//document that handles only filesuffix suffixes
Copyfileandaddpackagename (Files[i]);
Filelist.add (Files[i]);//Add to file collection
}
}
}
}


Method two JSP deletes all folders and file code for the directory

Import java.io.*;

public class DeleteAll {//Delete all contents under folder, including this folder
public void Delall (File f)
Throws IOException {
if (!f.exists ())//folder does not exist throw new IOException (specified directory does not exist: +f.getname ());

Boolean rslt=true;//Save Intermediate results
if (!) ( Rslt=f.delete ()) {//First try to delete//If the folder is not empty. Enumerate, recursively delete contents inside
File subs[] = F.listfiles ();
for (int i = 0; I <= subs.length-1; i++) {
if (Subs[i].isdirectory ())
Delall (Subs[i]);//delete subfolder contents recursively
Rslt = Subs[i].delete ();//delete subfolder itself
}
Rslt = F.delete ();//delete this folder itself
}

if (!RSLT)
throw new IOException (Unable to delete: +f.getname ()); Return
}

public static void Main (string[] args) {
DeleteAll da= new DeleteAll ();
try {
Da.delall (New File (Somedir));
}
catch (IOException ex)
{
Ex.printstacktrace (); }
}}

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.