Whats the difference between a PrintWriter and a BufferedWriter. In what cases should we use them? or can we just choose anyone of them?
Printable View
Whats the difference between a PrintWriter and a BufferedWriter. In what cases should we use them? or can we just choose anyone of them?
Directly from the BufferedWriter class:
Another thing is that the PrintWriter does not have the ability to write raw bytes at a time, which if you need to encode the message you cannot do.Quote:
Without buffering, each invocation of a print() method would cause characters to be converted into bytes that would then be written immediately to the file, which can be very inefficient.
hmm.So can i say generally we should use BufferedWriter?
They are not really comparable classes.
A BufferedWriter is a wrapper class to provide buffering to any object of type Writer.
A PrintWriter is a specialised type of Writer that to quote the API docs "Prints formatted representations of objects to a text-output stream"