-3

PrintStream

  1. write() overloaded methods of PrintStream
  2. print() overloaded methods of PrintStream

PrintWriter

  1. write() overloaded methods of PrintWriter
  2. print() 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 ?

u32i64
  • 2,384
  • 3
  • 22
  • 36

1 Answers1

1

print() formats the output, while write() just prints the characters it is given. print() handles many argument types, converting them into printable strings of characters with String.valueOf(), while write() 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, while print(int) converts the integer into a character string.

write(49) prints:

1

print(49) prints:

49

DIF
  • 2,470
  • 6
  • 35
  • 49