title: Get file full path in java
body: <p>When I pass <code>File file</code> to a method I'm trying to get its full path like <code>file.getAbsolutePath();</code> I always get the same result no matter which one I use either absolute or canonical path <code>PATH_TO_MY_WORKSPACE/projectName/filename</code> and it is not there, how can I get exact location of the file?</p>
  
  <p>Thank you</p>
  
  <p><strong>DETAILS:</strong></p>
  
  <p>Here is some code and this solutions(its bad but its working):</p>
  
  <pre><code> private static void doSomethingToDirectory(File factDir) throws IOException {
              File[] dirContents = factDir.listFiles();
  
              if(factDir.isDirectory() &amp;&amp; dirContents.length &gt; 0){
                  for (int i = 0; i &lt; dirContents.length; i++) {
                      for (String str : dirContents[i].list()) {
                          if(str.equals(TEMP_COMPARE_FILE)){
                              process(new File(dirContents[i].getAbsolutePath() + "\\" + str));
                          }
                      }
                  }           
              }
          }
  </code></pre>
  
  <p>I'm looping trough directories where factDir is <code>src/main</code>, I'm seeking toBeProcessed.txt files only that is TEMP_COMPARE_FILE value and I'm sending them to process method which reads the file and does processing of it.</p>
  
  <p>If someone could better solution I'd be greatful</p>