Notice also that the first FileOutputStream instance is not created inside the try-with-resources block. That means that the try-with-resources block will not automatically close this FileOutputStream instance. However, when the OutputStreamWriter is closed it will also close the OutputStream instance it writes to, so the FileOutputStream instance will get closed when the OutputStreamWriter is closed.