Operations on files in JSP

Source: Internet
Author: User
Document directory
  • HTML tags and JavaScript tutorial

HTML tags and JavaScript tutorial


Operations on files in JSP

JSP
File Operations

JSP
File operations are very important. To describe the attributes of a file, you must use
File
Class, its method does not involve reading and writing files, but it is very important to describe the files.
1.

Create
File
Object
File (string filename)
Create a file object with a file name
File (string directpath, string filename)
Create an object using the path and file name of the file storage
File (file F, string filename)
Create an object with a file object and a file name
NOTE: If no path or directory is specified, the new file is located in the default directory of the server.
2.

Create directory
Public Boolean mkdir ()
3.

List Files And Directories
Public String [] list ()
List Files And Directories In String Array Mode
Public file [] list ()
To
File
Object method to list files and directories
4.

List objects and directories with specified conditions
Public String [] list (filenamefilter OBJ)
Public String [] list (filenamefilter OBJ)
Filenamefilter
Is an interface, which has
Accept
Method
Public Boolean accept (flie Dir, string name)
In a specific application: when listing a specified type, you must declare a class to implement
Filenamefilter
Interface
Accept
Method. In the following program film, first instantiate
File
Object, specify the directory, instantiate the class that implements the interface, and take this as a parameter to form
Filenamefilter
Object, followed by calling
List
Or
Listfile
Method To list specified files.
Program example:
<% @ Page Language = "Java" %>
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page errorpage = "" %>
<% @ Page import = "Java. Io. *" %>
<! Doctype HTML public "-// W 3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> file filter </title>
</Head>
<Body bgcolor = "# ffffff">
<%! Class filefilterjsp implements filenamefilter
{String STR = NULL;
Filefilterjsp (string S)
 


{STR = "." + S ;}
Public Boolean accept (File Dir, string name)
 


{Return name. endswith (STR );}//
Statement
Filefilterjsp
Class implementation
Filenamefilter
Interface
Accept
Method
} %>
<% File dir = new file ("G :/
Personal Materials
/
Design
");
Filefilterjsp file_jsp = new filefilterjsp ("jpg ");//
Instantiation
Filefilterjsp
Class, indicating the suffix of the file
String file_name [] = dir. List (file_jsp );//
By instantiating
File_jsp
List required file names
For (INT I = 0; I <file_name.length; I ++)
 


{Out. Print ("<br>" + file_name [I]);}
 
%>
</Body>
</Html>
 

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.