Change to PrintWriter to avoid buffering