title: How to get absolute path of files outside the current working directory [java]
body: <p>I'm trying to read a file outside my current working directory using <code>File</code> and <code>URL</code> classes in Java. I know that the current working directory is 'represented' by a <code>.</code> by default.</p>
  
  <p>Assuming my Java class is under <code>/folders/Desktop/MyClass.java</code>, if I want to read a file <code>file1.txt</code> in <code>/folders/Desktop/file1.txt</code>, I can do the following:</p>
  
  <pre><code>URL url = getClass().getResource("./file1.txt");  /* or "./anotherFolder/../file1.txt", or simply "file1.txt"*/
  File f = new File(url.getPath());
  </code></pre>
  
  <p>and everything works as expected.</p>
  
  <p>But what should I do to read a file that is not inside the current working directory and that is not inside a subdirectory of it? For example, if the file's path is <code>/folders/file1.txt</code>? I searched everywhere, but can't find anything. I tried <code>../file1.txt</code>, <code>./../file1.txt</code> and others, but nothing works. Maybe I missed something, or maybe I haven't searched in the right places.</p>