title: Java Servlets - Writing to file
body: <p>I'm using the Netbeans IDE, and I'm currently using a <a href="https://en.wikipedia.org/wiki/GlassFish" rel="nofollow noreferrer">GlassFish</a> server.
  What I want to do is <strong>write to a file</strong>.</p>
  
  <p>I looked at some pages, and the code I have now (that is not working as far as I know) looks like:</p>
  
  <pre><code> File outputFile = new File(getServletContext().getRealPath("/")
              + "TheFile.txt");
      FileWriter fout = new FileWriter(outputFile);
      fout.write("The Content");
      fout.close();
  </code></pre>
  
  <p>This is my project's structure:</p>
  
  <p><img src="https://i.stack.imgur.com/RLabQ.png" alt="alt text"></p>
  
  <p>Also where will the file get placed?</p>
  
  <hr>
  
  <p>Edit:
  I forgot to mention there are some other folders below the ones in the picture: Test Packages, Libraries, Test Libraries and Configuration Files. However I don't think the file would get placed there.</p>
  
  <p>Edit (newest):
  I found out the file is stored in the /build/web folder, but this is not appearing in Netbeans. Even after I restarted it.</p>