title: How do I get the path to a file in Java Servlet
body: <p>I'm creating a simple web app on my local machine using XAMPP. Basically, I want to check if a file exists, but I do not know how to get the path of the file.</p>
  
  <p>If I do the following, it will say that this file exists, which is true.</p>
  
  <pre><code>String path = "C:\\Users\\user\\Desktop\\ProjectName\\web\\files\\filename.txt";
  </code></pre>
  
  <p>However, this path is no good if I move the project from one computer to another, as the path won't be the same. What I'm asking is, what is the shortcut that I can use to get the location of the file. I know in PHP it would be something like</p>
  
  <pre><code>path = base_url()."files\filename.txt";
  </code></pre>
  
  <p>I can't really put into words what I am trying to ask, but I think people will get the idea. </p>
  
  <p>Edit:</p>
  
  <p>I'm using Netbeans too if that makes any difference.</p>