Java Reference
In-Depth Information
import java.io.*;
/**
* Demonstrate stream wrapping by writing text to the
* console using the standard output from System.out
* wrapped with OutputStreamWriter and PrintWriter.
**/
public class PrintWriterApp
{
public static void main (String args[]) {
// The System.out standard output stream is already
// opened by default. Wrap in a new writer stream to
// obtain 16 bit capability.
OutputStreamWriter writer =
new OutputStreamWriter (System.out);
// In turn, wrap the PrintWriter stream around this
// output stream and use the second parameter in the
// constructor to turn on the autoflush.
PrintWriter print - writer = new PrintWriter (writer, true);
// PrintWriter does autoflushing and offers a println
// method that includes line return.
print - writer.println ("Text output with PrintWriter.");
print - writer.println ("Primitives converted to strings:");
boolean a - boolean = false;
byte a - byte = 114;
short a - short = 1211;
int an - int = 1234567;
long a - long = 987654321;
float a - float = 983.6f;
double a - double = -4.297e-15;
print - writer.println (a - boolean);
print - writer.println (a - byte);
print - writer.println (a - short);
print - writer.println (an - int);
print - writer.println (a - long);
print - writer.println (a - float);
print - writer.println (a - double);
// PrintWriter doesn't throw IOExceptions but instead
// offers the catchError() method. The following could
// be placed after each invocation of a PrintWriter method.
 
Search WWH ::




Custom Search