listfile.jsp

来自「jsp动态网站开发与实例(第3版) 源码」· JSP 代码 · 共 44 行

JSP
44
字号
	<%@page contentType="text/html"%>
	<%@page pageEncoding="Ms950"%>
	<%@page import="java.io.*"%>
	<html>
	    <head><title>列举目录与文件结构</title></head>
	    <body>
	    <%
	        String strB = "";
	        String strBe = "";
	
	        String thePath=request.getRealPath("/") ; 
	        File myFile = new File(thePath)   ;
	        File[] objFiles = myFile.listFiles() ;
	        out.println(
	                "列出目录 "+thePath+" "+
	                "底下的所有目录及文件(粗黑体部份为目录,其余为文件):" + 
	                "<BR><HR>" );
	
	        for(int i=0 ; i <objFiles.length ; i++){
	            if (objFiles[i].isDirectory()){
	                strB = "<B>" ;
	                strBe = "</B>"  ;
	            }else{
	                strB = "" ;
	                strBe = "" ;
	            }
	            out.println(strB + objFiles[i].toString() + 
	 					strBe+ "<BR>");
	        }
	        out.println("<BR><HR>");
	        out.println("当前目录 "+thePath+" 的上层目录为 :");
	        out.println( myFile.getParentFile().toString() +
	 				 "<BR><BR>");
	        
	        out.println("以下列出当前系统的根目录:"+ "<BR><HR>" );
	        File[] myroot = File.listRoots() ;
	        
	        for(int i=0 ; i <myroot.length ; i++){
	            out.println( myroot[i].toString() + "<BR>");
	        }
	    %>
	    </body>
	</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?