• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PrintWriter write() and println() method query

 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just realized that PrintWriter has both write() and println() method.
Any idea what is the difference between them and which function to use when ?

 
Shwetha Sharma
Ranch Hand
Posts: 34
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply
Understood
 
praneeth ram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic