| Author |
PrintWriter write() and println() method query
|
Abhay Agarwal
Ranch Hand
Joined: Feb 29, 2008
Posts: 655
|
|
Just realized that PrintWriter has both write() and println() method.
Any idea what is the difference between them and which function to use when ?
|
Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
|
 |
Shwetha Sharma
Ranch Hand
Joined: Jun 01, 2008
Posts: 34
|
|
PrintWriter.println(String)
This method prints null if the argument passed to it is null.
PrintWriter.write(String)
This method throws a null pointer exception if the argument is null.
Apart from this it works the same as the write method except that it appends "\n" to the string argument.
Also the println method throws IOException while the PrintWriter.write doesn't throw IOException
|
SCJP6:80%, OCWCD 88 %
|
 |
Abhay Agarwal
Ranch Hand
Joined: Feb 29, 2008
Posts: 655
|
|
Thanks for the reply
Understood
|
 |
praneeth ram
Ranch Hand
Joined: Sep 21, 2009
Posts: 56
|
|
why we can use write() method in the case of AJAX why not println() method.
could you please explain it.
Thanks,
Praneeth.
SCJP,SCWCD.OCP.
|
 |
 |
|
|
subject: PrintWriter write() and println() method query
|
|
|