title: Java : download file outside server context
body: <p>I need to save a file and download file in directory outside server context.
  I am using <code>Apache Tomacat</code>
  I am able to do this in directory present in webapps directory of application</p>
  
  <p>If my directory structure is as follows,</p>
  
  <pre><code>--src
  --WebContent
      -- uploaddir
           -- myfile.txt
  </code></pre>
  
  <p>Then I am able to download in by simply.</p>
  
  <pre><code>      &lt;a href="uploaddir/myfile.txt" target="_blank"&gt;download&lt;/a&gt;
  </code></pre>
  
  <p>But, problem is when file is in some other directory say <code>d:\\uploadedfile\\myfile.txt</code></p>
  
  <p>then I wont be able to download it, as resource is not in server context as above.</p>
  
  <p>I have file path to uuid mapping,
  like,</p>
  
  <p><code>d:\\uploadedfiles\\myfile.txt &lt;-&gt; some_uuid</code></p>
  
  <p>then I want file should be downloaded, on click of following,</p>
  
  <pre><code>   &lt;a href="filedownloadservlet?ref_file=some_uuid"&gt;download&lt;/a&gt;
  </code></pre>
  
  <p>So, How to make file downloadable  when it is outside the server context,
  I heard about <code>getResourceAsStream()</code> method which would do this , But would any one help me on how to do this, probably with simple code snippet?</p>