Java.io.Printstream Class in Java | Set 2 (original) (raw)

Last Updated : 01 May, 2024

Java.io.Printstream Class in Java | Set 1

**More Methods:

**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 output stream
*Throws:
IllegalFormatException
NullPointerException
Java `
//Java program to demonstrate printf method
import java.io.
;
import java.util.Locale;
class PrintStreamDemo
{
public static void main(String[] args)
{
String s = "for";

    // create printstream object  
    PrintStream printStream = new PrintStream(System.out);  
      
    // illustrating printf(Locale l, String format, Object... args) method  
    printStream.printf(Locale.US, "Geeks%sGeeks", s);  
}  

}
`
**Output:
GeeksforGeeks

**Parameters:
format - A format string as described in Format string syntax
args - Arguments referenced by the format specifiers in the format string.
**Returns:
This output stream
*Throws:
IllegalFormatException
NullPointerException
Java `
//Java program to demonstrate printf(String format, Object... args) method
import java.io.
;
public class PrintStreamDemo
{
public static void main(String[] args)
{
String s = "for";

    // create printstream object  
    PrintStream obj= new PrintStream(System.out);  
      
    // illustrating printf(String format, Object... args) method  
    obj.printf("Geeks%sGeeks", s);  
}  

}
`
**Output:
GeeksforGeeks

}
`
**Output:
GeeksforGeeks

}
`
**Output:
g

}
`
**Output:
GEEK

}
` **Output:
5.42762

}
` **Output:
5.168502f

}
` **Output:
5

}
` **Output:
123456789

}
` **Output:
java.io.PrintStream@15db9742

}
` **Output:
GeeksforGeeks

}
` **Output:
BCD

**Overrides:
write in class FilterOutputStream
*Parameters:
buf - A byte array
off - Offset from which to start taking bytes
len - Number of bytes to write
Java `
//Java program to demonstrate write(int b) method
import java.io.
;
public class PrintStreamDemo
{
public static void main(String[] args)
{
byte c = 65;

    // create printstream object  
    PrintStream obj = new PrintStream(System.out);  
      
    //illustrating write(int b)  
    obj.write(c);  
  
    // flush the stream  
    obj.flush();  
  
}  

}
` **Output:
BCD

}
` **Output:
A