printWriter write4 Example
printWriter class write example. This example shows you how to use write method.
PrintWriter class write example. .write() method in the program takes string value either directly or through the variable in its constructor and writes the result in the file specified and not on the console output.
Here is the code:-
/**
* @Program uses write method to write String value in to
* the file specified.
* Write4.java
* Author:-RoseIndia Team
* Date:-7-july-2008
*/
import java.io.IOException;
import java.io.PrintWriter;
public class Write4 {
public static void main(String args[]) throws IOException {
PrintWriter out = new PrintWriter("c:\Hallow.doc");
String str0 = "welcome", str1 = "to", str2 = "roseindia", str3 = ".net";
out.write(str0 + " " + str1);
out.write(" " + str2 + str3);
out.flush();
}
} |
Output of the program:-
method writes result in the file and not on console
|