 <p>Your <code>outfile2</code> is a <code>PrintWriter</code>. Somewhat surprisingly, <a href="http://docs.oracle.com/javase/8/docs/api/java/io/PrintWriter.html" rel="nofollow"><code>PrintWriter</code> methods don't throw exceptions</a>.</p> <blockquote> <p>Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError().</p> </blockquote> <p>That explains why your first code doesn't throw <code>IOException</code>.</p> <p>In your second code, you add a call to <code>readLine()</code>, probably from a <code>BufferedReader</code>, that does throw <code>IOException</code>.</p>