Java Console writer() Example
Console class writer() method example. This example shows you how to use writer() method.
Syntax is : public PrintWriter writer()
This method retrieves the unique PrintWriter object associated with this console and returns the printwriter associated with this console.
Here is the code.
/**
* @(#) WriterConsole.java
* A class representing use of method writer() of Console class in
java.io Package.
* @Version 11-June-2008
* @author Rose India Team
*/
import java.io.*;
public class WriterConsole {
public static void main(String[] args) {
//Create a console object.
Console objConsole = System.console();
if (objConsole != null) {
// reader method call.
PrintWriter out = objConsole.writer();
out.println("Test regular writing!");
} else {
throw new RuntimeException("Can't run w/out a console!");
}
}
} |
|