title: How to write to a txt file in Servlet and automatically download it when requests
body: <p>I want to create a txt file in my Servlet and automatically download it at the client side when client requests. I have below code to write to a txt, but it gives access denied error in Netbeans IDE using glassfishserver. How can I do it?</p>
  
  <pre><code> //File creation
   String strPath = "C:\\example.txt";
   File strFile = new File(strPath);
   boolean fileCreated = strFile.createNewFile();
   //File appending
   Writer objWriter = new BufferedWriter(new FileWriter(strFile));
   objWriter.write("This is a test");
   objWriter.flush();
   objWriter.close();
  </code></pre>