JSP programming methods for obtaining files and directories and Windows disk characters in the current directory _jsp programming

Source: Internet
Author: User
Tags strlen stringbuffer

This article illustrates how JSP programming obtains files and directories and Windows disk characters in the current directory. Share to everyone for your reference, specific as follows:

(i) Get the files and directories in the current directory

Knowledge points

1 Application of the file object
2 Listfiles () method
3 Isdirectory () method, Isfile () method to determine whether a directory or file
4 Conversion String Method tostring

(1) Create a File object dir,
Then use the Listfiles () method to return all files in the current directory

String Path=request.getrealpath ("/");
File Dir=new file (path);
File File[]=dir.listfiles ();

(2) The loop determines whether the returned is a directory and displays it:

<% for
(int i=0;i<file.length;i++)
{
  if (file[i].isdirectory ())//
  Out.print ("<br>" + File[i].tostring ());
}
%>

(3) The loop determines whether the returned is a directory and displays it:

<% for
(int i=0;i<file.length;i++)
{
  if (File[i].isfile ())
  out.print ("<br>" +file[ I].tostring ());
}
%>

Program:

<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.io.*"%>
 
 

(ii) Get Windows drive letter

<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.io.*"%>
 
 

(iii) integration of two procedures

<%@ page contenttype= "text/html;charset=gb2312"%> <%@ page import= "java.io.*,java.util.*,java.net.*"%>
<%! Private final static int languageno=0;
Language version, 0: Chinese; 1: English string[] strdrivers = {"Drive", "Drivers"};
String[] strcurrentfolder= {"Current directory", "Present Folder"};
%>  

Our further optimizations, implementation

<%@ page contenttype= "text/html; CHARSET=GBK "%> <% @page import=" java.io.*,java.util.*,java.net.* "%>  

I hope this article will help you with JSP programming.

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.