title: How do I read text file and output in Servlet?
body: <p>i have file: input.txt 
  I want to read this file, put values in new output.txt from input.txt.</p>
  
  <p>Servlet.java</p>
  
  <pre><code>protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/plain");
      response.setHeader("Content-Disposition",
                   "attachment;filename=output.txt");
      PrintWriter out = response.getWriter();
      ServletContext cntxt = this.getServletContext();
      String fName = "/input.txt";
      InputStream ins = cntxt.getResourceAsStream(fName);
      try {
          if(ins != null){
          InputStreamReader isr = new InputStreamReader(ins);
          BufferedReader reader = new BufferedReader(isr);
          int n = 0;
          String word ="";
          while((word= reader.readLine())!= null)
           {
               n = Integer.parseInt(word);
               out.println(n);
           }
        } finally {
              out.close();
        }
  }
  </code></pre>
  
  <p>but output.txt is empty. What's wrong?</p>