Code for Traversing files in a folder Using JSP

Source: Internet
Author: User

Displayfile. Java

//*********************************
File parentdirectory = NULL; // Current Directory
Arraylist [] file = NULL; // stores all files in the current directory
Arraylist [] Directory = NULL; // stores all directories in the current directory
String [] temp = NULL; // temporary array stores all files in the current directory and the absolute path of the Directory plus the string with the complete name
File tempfile = NULL;

If (request. getparameter ("directory") = NULL)
{
Parentdirectory = new file ("C: // Temp"); // use the default directory for accessing objects using Servlet for the first time

}
Else
{
// The Directory submitted on the page for the second or later access is the default directory
Parentdirectory = new file (request. getparameter ("directory "));//
}

Temp = parentdirectory. List (); // extract the absolute path of all files and directories in the current directory and add the string with the complete name

For (INT I = 0; I <list. Length (); I ++ ){
// Check whether the directory is put into the directory set and the files are put into the file set
Tempfile = new file (temp)
If (tempfile. isdirectory ())
Directory. Add (tempfile );
Else
File. Add (tempfile );
}

//*********************************

Then, use the two sets on the JSP page to display the Directory and file directory. You can use the super connection to call the servlet above again.

"Displayfile? Directory = <% (File) file. Get (I). getname () %>"

If there is no environment, it is inevitable that there will be a problem ~~~~

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.