title: Download file from servlet through browser
body: <p>I should download a csv file from the server through browser.
  I try with servlet with following code</p>
  
  <pre><code>private void writeFile(String filename, String content, HttpServletResponse response) throws IOException {
  
  
      String filename="VR.csv";
       try {
       File file = new File(filename);
  
  
       FileWriter fw = new FileWriter(file);
       BufferedWriter bw = new BufferedWriter(fw);
       bw.write(content);
       bw.flush();
       bw.close();
       }
       catch(IOException e) {
       e.printStackTrace();
       }
  
  
       // This should send the file to browser
       ServletOutputStream out = response.getOutputStream();
  
      FileInputStream in = new FileInputStream(filename);
       byte[] buffer = new byte[4096];
       int length;
       while ((length = in.read(buffer)) &gt; 0){
          out.write(buffer, 0, length);
       }
       in.close();
       out.flush();
  
  
  
      System.out.println("done"); 
  
  }
  </code></pre>
  
  <p>But the program doesn't download any file in Download folder, program let me see in the browser the csv content. I need to have the VR.csv in the download folder of the browser.</p>