title: How to Read file from a shared location Windows? (Java)
body: <p>Is there a way to read a file from a network shared location on windows?</p>
  
  <p>Let's say for instance I've this simple code that reads a text file called <strong><em>readMe.txt</em></strong> from the <strong><em>Addons</em></strong> folder. </p>
  
  <pre><code>import java.io.File;
  
  class Sample{
  
      public static void main(String[] ar){
          File file = new File("Addons/ReadMe.txt");
          System.out.println(file.getAbsolutePath());
        //followed by printing the contents of file   
      }
  }
  </code></pre>
  
  <p>And I execute this file using a windows batch <strong><em>runme.bat</em></strong> that has </p>
  
  <pre><code>java Sample
  PAUSE
  </code></pre>
  
  <p>The bat runs and executes the above class only when I place the Addons folder with ReadMe.txt, Sample.class, runme.bat file in my local drive. </p>
  
  <p>When it is placed in a network shared location with UNC path like <strong><em>\\name\Shared</em></strong></p>
  
  <p>In such a scenario, the bat file typically starts the base from <strong><em>C:\Windows</em></strong> and throws a classNotFoundException. I can rather map the shared drive to a <strong>*Z:*</strong> drive or whatever but I do not want to do it. </p>
  
  <p>I want the code to programatically detect and retrieve the content of Readme.txt in Addons folder irrespective of whether it is being executed on a local drive or on a shared drive. Is there a way to achieve this? Please help..</p>
  
  <blockquote>
    <p>Thanks</p>
    
    <p>Veekay</p>
  </blockquote>