PrintStream Printf() Example
A convenience method to write a formatted string to this output stream using the specified format string and arguments.
PrintStreamclass Printf() method example. This example shows you how to use Printf() method.This method gives A convenience method to write a formatted string to this output stream using the specified format string and arguments.
Here is the code:-
/**
* @Program that shows method to write a formatted string to this output stream
* using the specified format string and arguments.
* Printf.java
* Author:-RoseIndia Team
* Date:-10-Jun-2008
*/
import java.io.*;
import java.util.*;
public class Printf {
public static void main(String[] args) throws IOException {
Locale l=new Locale("English");
String s="rose";
//Creating FileOutputStream object
FileOutputStream out = new FileOutputStream("text.txt");
FileInputStream fin = new FileInputStream("text.txt");
//Creating PrintStream object
PrintStream ps = new PrintStream(out);
//Shows method to write a formatted string to this output stream
ps.printf(l, s, new String(""));
System.out.println("Formatted string : ");
System.out.println((char)fin.read());
System.out.println((char)fin.read());
System.out.println((char)fin.read());
System.out.println((char)fin.read());
}
} |
Output of the Program
Formatted string :
r
o
s
e |
|