How can I write HTTP Request Body to a file in a Java Web App?
<p>This is the code I have:</p>

<pre><code>@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    final ServletInputStream inputStream = req.getInputStream();
    int read;
    File file = new File("koray.txt");
    final FileOutputStream fileOutputStream = new FileOutputStream(file);
    while ((read = inputStream.read()) != -1) {
        fileOutputStream.write(read);
    }
    fileOutputStream.flush();
    fileOutputStream.close();
}
</code></pre>

<p>When I get a HTTP Request like this:</p>

<pre><code>beer-characteristics=ğ
</code></pre>

<p>in koray.txt I will see:</p>

<pre><code>beer-characteristics=%C4%9F
</code></pre>

<p>Well c49f seems to be the utf-8 hex value for 'ğ' but why am I seeing the hex value in the file, but not the 'ğ' itself?</p>

<p>Edit: This does not work either:</p>

<pre><code>final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
while ((read = in.read()) != -1) {
    outputStreamWriter.write(read);
}
</code></pre>