title: Reading files from relative paths on Tomcat
body: <p>I need to run a web-app on Tomcat, but it cannot read the txt files(from a relative paths as below) on Tomcat. However, it does work if I use a full path. </p>
  
  <p>So I am wondering where can I put these txt files so that when Tomcat started, the app can successfully read the txt files from a relative path. </p>
  
  <p>Currently, the <strong>project structure</strong> is as follows, the <strong>txt files</strong> is located on the same directory as <strong>src file</strong> in Project Explorer <strong>in Eclipse</strong>.</p>
  
  <pre><code>Project_Name
  src
     java files
  
  EDGES.txt
  NODES.txt
  </code></pre>
  
  <p>The code is as follows, I am appreciated if someone can give me an answer in details, since I am quite new to Java. </p>
  
  <p>The <strong>code</strong> is as follows:</p>
  
  <pre><code>public class RouteingDao {
      NodeJSONReader nodeInput = new NodeJSONReader("NODES.txt");
      EdgeJSONReader edgeInput = new EdgeJSONReader("EDGES.txt");
      ...
  }
  </code></pre>
  
  <p>The <strong>NodeJSONReader/EdgeJSONReader</strong> class is as follows:</p>
  
  <pre><code>public class EdgeJSONReader {
      private EdgeEntity[] edgeEntity;
  
      // constructor
      public EdgeJSONReader(String JSON_FILE) {
          edgeEntity = readEntityFromFile(JSON_FILE);
      }
  
      // load the JSON data from local file 
      public EdgeEntity[] readEntityFromFile(String JSON_FILE) {
          try {
              Reader reader = new FileReader(JSON_FILE);
              Gson gson = new Gson();
              edgeEntity = gson.fromJson(reader, EdgeEntity[].class);
          } 
          ...
      }
  }
  </code></pre>