0

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?

2
  • may be this is your soluction : stackoverflow.com/questions/2395737/… Commented Jun 2, 2019 at 6:56
  • Tidied up code layout and typing. Commented Jun 2, 2019 at 9:52

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

as i understood from you that text files i used in my project not contained in WAR files that i will deploy to server, and i should upload separately. is it right?
That is exactly that.
how can i add path in code for this text files that i want to read from it after upload separately to server? @ davidxxx
You don't add this path, you zip it from the client side and then you send a HTTP post request with this zip. In the link I referenced. in the html, form using the param enctype="multipart/form-data" is generally a common way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.