PrintWriter format Example
PrintWriter class format example. This example shows you how to use format method.
PrintWriter class format example. public PrintWriter format(String format, Object... args) Writes a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer.
Here is the code
/**
* @ # Format.java
* A class reprsenting use to format method
* of PrintWriter class in java.io package
* version 12 June 2008
* author Rose India
*/
import java.io.*;
public class Farmat1 {
public static void main(String args[]) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
int i = 0;
printWriter.format("i = %d",i);
System.out.println(stringWriter.getBuffer());
}
} |
|