PrintStream
write()overloaded methods of PrintStreamprint()overloaded methods of PrintStream
PrintWriter
write()overloaded methods of PrintWriterprint()overloaded methods of PrintWriter
I don't understand that if both write() method and print() method doing the same thing (writing to file) then why this two name is defined in those classes ?
print()formats the output, whilewrite()just prints the characters it is given.print()handles many argument types, converting them into printable strings of characters withString.valueOf(), whilewrite()just handles single characters, arrays of characters, and strings.To illustrate the difference,
write(int)interprets the argument as a single character to be printed, whileprint(int)converts the integer into a character string.write(49)prints:print(49)prints: