title: Path for creating a file in Tomcat
body: <p>I created a website setting file in the xml format, and the content of this file specifies things like website title, url, meta description, admin email, etc.</p>
  
  <p>In my Java code, I simply defined the file as following:</p>
  
  <pre><code>private static final String webSettingFileName = "WebSettings.xml";
  
  public void saveSetting()
  {
      File settingFile = new File(webSettingFileName);
      // try-catch block to write the XML file omitted
  }
  </code></pre>
  
  <p>After I deploy the war file, I found out that the web Setting xml file was written to the Tomcat bin folder, however, I would like to write the file inside the ROOT folder of webapps in Tomcat. So I am wondering how to specify the file path in my code. Thanks</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>As Jarrod Roberson gave me a red -1 for duplicate question. I disagree with him, because I had checked the post before making this post. I tried the method suggested in <a href="https://stackoverflow.com/questions/10802242/create-temp-files-in-tomcat-webapps-folder">that post here</a>, but it does not work for me, because I need to save the web settings file persistently in the same location no matter how many times Tomcat has restarted (so tomcat/webapps serves my purpose!). The file is for saving website settings. In addition, the ServletContext don't seem working in Java 1.8 that I am using for my webapp.</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>This is how I finally made it work: </p>
  
  <pre><code>private final static File catalinaBase = new File(System.getProperty("catalina.base")).getAbsoluteFile();
  private static final String webSettingFileName = "WebSetting.xml"; 
  private final static File file = new File(catalinaBase, "webapps/" + webSettingFileName); 
  </code></pre>