简体   繁体   中英

how list all files from directory in java web application?

I implemented a java web application using html page and servlet classes. In servlet class, I need to read a list of files one by one from a specific directory in the project as follows:

    File folder = new File("C:\\Users\\Alahram\\Desktop\\latest RC2\\latest 
RC2\\RC2\\src\\docs\\");

    File[] files = folder.listFiles();

It works correctly from an absolute path on localhost, but I need to use relative path for this directory to be able upload this project to the server. Can anyone help me in this problem?

The application container (Tomcat, Jetty or any other) started on a specific host cannot access to filesystem of the client of a distinct host that uses it through its browser for obvious physical (a machine don't see the filesystem of the other by default : these are not connected) and security reasons (we would not that either).
To be able to load this directory you should zip it from the client side and then send it via a HTTP request, what we commonly call upload . Then unzip it from the server side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM