Implementing "cat" in Java so that it will output raw bytes to System.out
<p>I am writing a very simple implementation of the <code>cat</code> function from unix in Java:</p>
<pre class="lang-java prettyprint-override"><code>public class Cat {
    public static void main(String[] args) {
        try {
            int ch;
            BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
            while ((ch = System.in.read()) != -1)
                log.write((char) ch);
            log.flush();
        } catch (IOException io) {
            io.printStackTrace();
        }
    }
}
</code></pre>
<p>When I pass a text file input like so, I get:</p>
<pre class="lang-none prettyprint-override"><code>$cat hello.txt | java Cat

this is
the second line
no jk the third
</code></pre>
<p>However when I pass in another kind of file like a jpg, it does not copy properly. I will pass in a jpg, but when I try to open it the error I get is:</p>
<pre class="lang-none prettyprint-override"><code>Error interpreting JPEG image file (Not a JPEG file: starts with 0xc3 0xbf)
</code></pre>
<p>I'm pretty naive when it comes to IO related stuff so I am having trouble figuring out what is going wrong. Am I not writing to standard output like I think I am?</p>