VOOZH about

URL: https://www.geeksforgeeks.org/java/java-io-printwriter-class-java-set-2/

⇱ Java.io.PrintWriter class in Java | Set 2 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java.io.PrintWriter class in Java | Set 2

Last Updated : 23 Jul, 2025
Java.io.PrintWriter class in Java | Set 1 More methods:
  • PrintWriter printf(Locale l, String format, Object... args) : A convenience method to write a formatted string to this writer using the specified format string and arguments.
    Syntax :public PrintWriter printf(Locale l,
     String format,
     Object... args)
    Parameters:
    l - The locale to apply during formatting. If l is null then no localization is applied.
    format - A format string as described in Format string syntax
    args - Arguments referenced by the format specifiers in the format string.
    Returns: This writer
    Throws:
    IllegalFormatException
    NullPointerException
    Output:
    GeeksforGeeks
  • PrintWriter printf(String format, Object... args) : A convenient method to write a formatted string to this writer using the specified format string and arguments.
    Syntax :public PrintWriter printf(String format,
     Object... args)
    Parameters:
    format - A format string as described in Format string syntax
    args - Arguments referenced by the format specifiers in the format string.
    Returns: This writer
    Throws:
    IllegalFormatException
    NullPointerException
    Output:
    GeeksforGeeks
  • void println(): Terminates the current line by writing the line separator string.
    Syntax :public void println()
    Output:
    GeeksforGeeks
  • void println(boolean x): Prints a boolean and then terminate the line.
    Syntax :public void println(boolean x)
    Output:
    true
    New Line
  • void println(char x): Prints a character and then terminate the line.
    Syntax :public void println(char x)
    Output:
    a
    b
  • void println(char[] x): Prints an array of characters and then terminate the line.
    Syntax :public void println(char[] x)
    Output:
    abc
    
  • void println(double x): Prints a double and then terminate the line.
    Syntax :public void println(double x)
    Output:
    176.348
  • void println(float x): Prints a float and then terminate the line.
    Syntax :public void println(float x)
    Output:
    5.76348
  • void println(int x): Prints an integer and then terminate the line.
    Syntax :public void println(boolean x)
    Output:
    15
    
  • void println(long x): Prints a long integer and then terminate the line.
    Syntax :public void println(long x)
    Output:
    1252344125
  • void println(Object x) :Prints an Object and then terminate the line.
    Syntax :public void println(Object x)
    Output:
    10
  • void println(String x) : Prints a String and then terminate the line.
    Syntax :public void println(boolean x)
    Output:
    GeeksforGeeks
  • protected void setError() : Sets the error state of the stream to true.
    Syntax :public void println(String x)
    Output:
    GHI
    
  • void write(char [] buf, int off, int len) : Writes len char from the specified char array starting at offset off to this stream.
    Syntax :public void write(char [] buf,
     int off,
     int len)
    Overrides:
    write in class FilterOutputStream
    Parameters:
    buf - A char array
    off - Offset from which to start taking char 
    len - Number of char to write
    Output:
    GHI
  • void write(int b) : Writes the specified char to this stream.
    Syntax :public void write(int b)
    Overrides:
    write in class Writer
    Parameters:
     b - The char to be written
    Output:
    F
  • void write(String s) : Writes a string.
    Syntax :public void write(String s)
    Parameters:
    s - String to be written
    
    Hello World
  • void write(String s, int off, int len) : Writes a portion of a string.
    Syntax :public void write(String s,
     int off,
     int len)
    Parameters:
    s - A String
    off - Offset from which to start writing characters
    len - Number of characters to write
    
HelloWorld
rt
Comment
Article Tags:
Article Tags: