title: File path or file location for Java - new file()
body: <p>I have the following structure for my project.</p>
  
  <p>In Eclipse:</p>
  
  <pre><code>myPorjectName
    src
      com.example.myproject
          a.java
      com.example.myproject.data
          b.xml
  </code></pre>
  
  <p>In <code>a.java</code>, I want to read <code>b.xml</code> file. How can I do that? Specifically, in <code>a.java</code>, I used the following code:</p>
  
  <pre><code>DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
  Document doc = docBuilder.parse (new File("data/b.xml"));
  </code></pre>
  
  <p>This code cannot find <code>b.xml</code>. However, if I change the path to <code>src/com/example/myproject/data/b.xml</code> then it works. The current location seems to be in the root of my project file. </p>
  
  <p>But I see other people's examples, <strong>if <code>b.xml</code> and <code>a.java</code> are in the same folder, then we can directly use <code>new File("b.xml")</code>.</strong> But I try putting <code>b.xml</code> in the same folder of <code>a.java</code> rather than putting in the sub folder, but it still <strong>does not work</strong>.  If this works, then in my case, I should be able to use <code>new File("data/b.xml")</code>, right? I really do not understand why this is not working.</p>