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.