title: Feedback form each time overwrites one text file with new incoming data
body: <pre class="lang-html prettyprint-override"><code>&lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;JSP Form&lt;/title&gt;
      &lt;style&gt;
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form action=&quot;TestFileHandling.jsp&quot; method=&quot;post&quot;&gt;
        &lt;fieldset&gt;
          &lt;legend&gt;User Information&lt;/legend&gt;
          &lt;label for=&quot;question&quot;&gt;Question&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;question&quot;/&gt;&lt;br/&gt;
          &lt;input type=&quot;submit&quot; value=&quot;submit&quot;&gt;
        &lt;/fieldset&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>The above is a simple form that lets the user enter a question before sending it.</p>
  <pre class="lang-html prettyprint-override"><code>&lt;%@page import=&quot;myPackage.FileReaderWriter&quot; %&gt;
  &lt;%@page import=&quot;java.util.Vector&quot; %&gt;
  
  &lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
           pageEncoding=&quot;ISO-8859-1&quot; %&gt;
  &lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; 
      &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%
      Vector&lt;String[]&gt; v = new Vector&lt;String[]&gt;();
      String[] str1 = {request.getParameter(&quot;question&quot;)};
      v.addElement(str1);
      FileReaderWriter.saveVectorToFile(v, &quot;MyTestFile.txt&quot;);
  %&gt;
  &lt;%
      Vector&lt;String[]&gt; vec = FileReaderWriter.readFileToVector(&quot;MyTestFile.txt&quot;);
      for (int i = 0; i &lt; vec.size(); i++) {
          out.print(&quot;|&quot;);
          for (int j = 0; j &lt; vec.elementAt(i).length; j++) {
              out.print(vec.elementAt(i)[j] + &quot;|&quot;);
          }
  %&gt;
  &lt;br&gt;
  &lt;%
      }
  %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>This part takes the question entered and saves it to a text file and then opens the file to display whatever is inside.</p>
  <p>All this is done through the following java code:</p>
  <pre class="lang-java prettyprint-override"><code>package myPackage;
  
  import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.Vector;
  
  public class FileReaderWriter {
      public static void saveVectorToFile(Vector&lt;String[]&gt; v, String sFileName) {
          try {
              // Create a new file writer
              FileWriter writer = new FileWriter(sFileName);
  
              // Loop through all the elements of the vector
              for (int i = 0; i &lt; v.size(); i++) {
                  // Capture the index of the last item of each array
                  int lastIndex = v.elementAt(i).length - 1;
                  // Loop through all the items of the array, except
                  // the last one.
                  for (int j = 0; j &lt; lastIndex; j++) {
                      // Append the item to the file.
                      writer.append(v.elementAt(i)[j]);
                      // Append a comma after each item.
                      writer.append(',');
                  }
                  // Append the last item.
                  writer.append(v.elementAt(i)[lastIndex]);
                  // Append a new line character to the end of the line
                  // (i.e. Start new line)
                  writer.append('\n');
              }
              // Save and close the file
              writer.flush();
              writer.close();
          }
          // Catch the exception if an Input/Output error occurs
          catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      public static Vector&lt;String[]&gt; readFileToVector(String sFileName) {
          // Initialise the BufferedReader
          BufferedReader br = null;
  
          // Create a new Vector. The elements of this Vector are String arrays.
          Vector&lt;String[]&gt; v = new Vector&lt;String[]&gt;();
          try {
              // Try to read the file into the buffer
              br = new BufferedReader(new FileReader(sFileName));
              // Initialise a String to save the read line.
              String line = null;
  
              // Loop to read all the lines
              while ((line = br.readLine()) != null) {
                  // Convert the each line into an array of Strings using
                  // comma as a separator
                  String[] values = line.split(&quot;,&quot;);
  
                  // Add the String array into the Vector
                  v.addElement(values);
              }
          }
          // Catch the exception if the file does not exist
          catch (FileNotFoundException ex) {
              ex.printStackTrace();
          }
          // Catch the exception if an Input/Output error occurs
          catch (IOException ex) {
              ex.printStackTrace();
          }
          // Close the buffer handler
          finally {
              try {
                  if (br != null)
                      br.close();
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
          }
          // return the Vector
          return v;
      }
  }
  </code></pre>
  <p>My problem is that although everything seems to be working, everytime I enter a new question the old one in the text file gets overwritten. Is there a way I can fix this so that every time I enter a new question in the form, it will get added to the textfile along with all the others instead of constantly overwritting it? Thanks for any information or help.</p>