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?

Nick
  • 4,820
  • 18
  • 31
  • 47

1 Answers1

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.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • 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? – shereen saleh Jun 02 '19 at 15:27
  • That is exactly that. – davidxxx Jun 02 '19 at 16:23
  • how can i add path in code for this text files that i want to read from it after upload separately to server? @ davidxxx – shereen saleh Jun 02 '19 at 19:48
  • 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. – davidxxx Jun 03 '19 at 17:32