title: Read File to String in Java Servlet
body: <p>I have a form in  my HTML page where users fill out two text fields or upload two files, and click a single button to submit. Here is the code for the form: </p>
  
  <pre><code>&lt;form name="submitButton" action="DAOserv" method="POST" enctype="multipart/form-data"&gt;
                  &lt;div id="SQL_form"&gt;
                      &lt;div &gt;
                          &lt;textarea name="SQL" placeholder="BAU Reason"
                              rows="11"&gt;&lt;/textarea&gt;
                          &lt;label for="BAUInputFile"&gt;BAU File&lt;/label&gt; &lt;input type="file"
                              id="BAUInputFile"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div &gt;
                      &lt;div &gt;
                          &lt;textarea name="BAU" placeholder="SQL Queries"
                              rows="11"&gt;&lt;/textarea&gt;
                          &lt;label for="SQLInputFile"&gt;SQL File&lt;/label&gt; &lt;input type="file"
                              id="SQLInputFile"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;button type="submit" &gt;Submit&lt;/button&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>To clarify, the first DIV contains the text box and file upload button for a set of Queries, and the second contains a text box and file upload button  for a business reason. The user must either upload a file or write into each of the two sections. </p>
  
  <p>The button click submits both of the form fields, but what I can't figure out or find a solution to online (most post talk about uploading the file to the servlet directory) is how to simply read the files to a string, <strong>when the user has uploaded a file to one or both of the two form fields</strong>. </p>
  
  <p>In essence, the servlet will check each text field, if it is null, it will check to see if there is a file that has been uploaded, and if so, it will parse the text in that file to a string. </p>
  
  <p>Thanks in advance for any help! </p>