MyEclipse------traverse (all or specific) files and directories under a path

Source: Internet
Author: User

Java files in the Usebean package (defined by itself, below the src folder)

Fileaccept.java

 PackageUsebean;ImportJava.io.File;ImportJava.io.FilenameFilter; Public classFileacceptImplementsfilenamefilter{PrivateString Extendname;  Public voidSetextendname (String s) { This. Extendname= "." +s; } @Override Public BooleanAccept (File dir, String name) {//TODO auto-generated Method Stub        returnName.endswith (extendname); }}

browserfile.jsp

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%    StringPath=Request.getcontextpath (); StringBasePath=Request.getscheme ()+ "://"            +Request.getservername ()+ ":" +Request.getserverport ()+Path+ "/";%><%@page Import="java.io.*" %><Jsp:usebeanID= "Use"Scope= "page"class= "Usebean." Fileaccept "/><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head><Basehref= "<%=basePath%>"><title>My JSP ' browserfile.jsp ' starting page</title></Head><Body>    <Fontstyle= "Font-weight:bold;font-family:microsoft Yahei">File browsing</Font><BR>    <%        intFcount=0, DCount=0; Path=Request.getrealpath (""); File D=NewFile (path); File list[]=D.listfiles (); /*        //return a specific file//Use is an object, equivalent to fileaccept use=Newfileaccept (); Use.setextendname ("JSP"); Stringlist[]=d.list (use);  for(intI=0; I<List.length;i++) {out.print (List[i]+"<br>"); }        */                /*        Stringlist[]=d.list ();//returns all directories and filenames as strings for(intI=0; I<List.length;i++) {out.print (List[i]+"<br>"); }        */                //output File Out.print (path+"files under the directory:"+"<br>");  for(intI=0; I<List.length;i++){            if(List[i].isfile ()) {Out.print (List[i].getname () )+"<br>"); Fcount++; }        }                        //Output Directory Out.print ("<br>"+Path+"Directory under directory:"+"<br>");  for(intI=0; I<List.length;i++){            if(List[i].isdirectory ()) {Out.print (List[i].getname () )+"<br>"); DCount++; }        }             %>     <H3style= "Color:blue">Statistical results:</H3>     <Center>Total Files:<%=Fcount%><BR>Total Directories:<%=DCount%>     </Center>     </Body></HTML>

MyEclipse------traverse (all or specific) files and directories under a path

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.