printWriter write5 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 a portion of this string as per passed indexes in to the file specified and not on the console output.
Here is the code:-
/**
* @Program uses write method to write a portion or set of
* String value as per passed indexes in to the file specified.
* Write5.java
* Author:-RoseIndia Team
* Date:-7-july-2008
*/
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class Write5 {
public static void main(String args[]) throws IOException {
PrintWriter out = new PrintWriter("c:\nest.doc");
String str0 = " welcome roseindia.net ";
out.write(str0, 1, 21);
out.close();
}
} |
Output of the program:-
result is writed in the file and not on the console.
|