title: Get current path of java file that is running
body: <p>I am trying to write a simple tcp client/server app that copies a file. I want to the server to list the files the client can copy. My code so far is this:</p>
  
  <pre><code>import java.io.*;
  public class GetFileList
  {
      public static void main(String args[]) throws IOException{
          File file = new File(".");  
          File[] files = file.listFiles();  
          System.out.println("Current dir : " + file.getCanonicalPath());
          for (int fileInList = 0; fileInList &lt; files.length; fileInList++)  
          {  
              System.out.println(files[fileInList].toString());  
          }
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Current dir : C:\Users\XXXXX\Documents\NetBeansProjects\Test
  .\build
  .\build.xml
  .\manifest.mf
  .\nbproject
  .\src
  .\UsersXXXXXDocumentsNetBeansProjectsTestsrcfile2.txt
  </code></pre>
  
  <p>My issue is that it is giving me the parent directory instead of the current directory. My GetFileList.java is located in <code>C:\Users\XXXXX\Documents\NetBeansProjects\Test\src</code> but it is showing <code>C:\Users\Alick\Documents\NetBeansProjects\Test</code>Can anyone help me fix this?</p>