title: Java filepath in tomcat
body: <p>I have a java application running on a tomcat server. The application needs to read/write xml files to a directory.</p>
  
  <p>I programmed it so that the files are written and read from the same directory using constant</p>
  
  <pre><code>public static final String DICTIONARY_PATH = getRelativePath() + "/res/dictionaries/";
  </code></pre>
  
  <p>which calls this method</p>
  
  <pre><code>public static String getRelativePath() {
      return new File("").getAbsolutePath();
  }
  </code></pre>
  
  <p>The constant is used in the methods <code>readFromFile(String language)</code> and <code>writeToFile(Dictionary dictionary)</code></p>
  
  <p>When calling these methods from the main method running in IntelliJ (for testing purposes) it works beautifully and reads and writes files to the specified folder.</p>
  
  <p>When these methods are called from the application when running on the tomcat server it can't find the files because it's looking in the <code>tomcat/bin</code> folder of tomcat while the files are located in <code>tomcat/webapps/application/WEB-INF/classes/dictionaries</code></p>
  
  <p>How can I implement the method <code>getRelativePath()</code> so that it works on both the tomcat server as locally in IntelliJ (by calling the main method)</p>