PrintStream Format() Example
Writes a formatted string to this output stream
PrintStreamclass Format() method example. This example shows you how to use Format() method.This method Writes a formatted string to this output stream using the specified format string and arguments.
Here is the code:-
/**
* @Program that Writes a formatted string to this output stream using the
* specified format string and arguments.
* Format.java
* Author:-RoseIndia Team
* Date:-10-Jun-2008
*/
import java.io.*;
import java.util.*;
public class Format {
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);
// Writes a formatted string to this output stream
ps.format(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 |
|