-1

I am creating a project using jsp/servlet in which I am trying to create java file and class file inside the project itself. But I am able to do this for only my system because the path I give their is like : C:\Users\MySystem\Desktop\Test\.. which works only for my system. What should I do so that if I have to run this project in another system I don't have to change path again and again.

1 Answers1

0

Well if it is maven project just put your resources files under src/main/resources and you can read them using this lines.

String path = Thread.currentThread().getContextClassLoader()
                    .getResource("yourFileName").getPath();
System.out.println(path);

Or even this way you can do it.

String pathOfTheFile = getServletContext().getResource("yourFile").getPath();

and don't forget to put the file under web-content or webapp folder

SparkOn
  • 8,806
  • 4
  • 29
  • 34