The present of FileOutputStream cause the InputStream.read error <p>I have some problem with Java IO, this code below is not working, the variable count return -1 directly.</p> <pre><code>public void putFile(String name, InputStream is) { try { OutputStream output = new FileOutputStream("D:\\TEMP\\" + name); byte[] buf = new byte[1024]; int count = is.read(buf); while( count &gt;0) { output.write(buf, 0, count); count = is.read(buf); } } catch (FileNotFoundException e) { } catch (IOException e) { } } </code></pre> <p>But if I commented the OutputStream such as</p> <pre><code> public void putFile(String name, InputStream is) { try { //OutputStream output = new FileOutputStream("D:\\TEMP\\" + name); byte[] buf = new byte[1024]; int count = is.read(buf); while( count &gt;0) { //output.write(buf, 0, count); count = is.read(buf); } } catch (FileNotFoundException e) { } catch (IOException e) { } } </code></pre> <p>The count will return the right value (>-1). How is this possible ? Is it a bug ?</p> <p>I'm using Jetty in Eclipse with Google plugins and Java 6.21 in Windows 7. PS :I change the original code, but it doesn't affect the question</p>