Java Methods of PrintWriter

htt‮.www//:sp‬theitroad.com

Here are some of the most commonly used methods of the PrintWriter class in Java:

  1. print(boolean b): This method prints a boolean value to the output stream.

  2. print(char c): This method prints a character to the output stream.

  3. print(int i): This method prints an integer value to the output stream.

  4. print(double d): This method prints a double value to the output stream.

  5. print(String s): This method prints a string to the output stream.

  6. println(): This method prints a newline character to the output stream.

  7. println(boolean x): This method prints a boolean value to the output stream, followed by a newline character.

  8. println(char x): This method prints a character to the output stream, followed by a newline character.

  9. println(int x): This method prints an integer value to the output stream, followed by a newline character.

  10. println(double x): This method prints a double value to the output stream, followed by a newline character.

  11. println(String x): This method prints a string to the output stream, followed by a newline character.

  12. printf(String format, Object... args): This method prints a formatted string to the output stream using the specified format string and arguments.

  13. format(String format, Object... args): This method is similar to printf() and prints a formatted string to the output stream using the specified format string and arguments.

  14. flush(): This method flushes the output stream, causing any buffered data to be written.

  15. close(): This method closes the output stream.

Note that many of these methods can throw an IOException if there is an error while writing to the stream. Therefore, it is important to handle exceptions appropriately when using these methods.