printWriter append2 Example
printWriter class append example. This example shows you how to use append method.
PrintWriter class append example. Append method generates sequence of char values in to the abstract pathname of file.Here ASCII notation is used in the PrintWriter contructor as second parameter due to which only ASCII notation char value will be allowed.
Here is the code:-
/**
* @Program uses append method to generate sequence
* of char values and to append them to PrintWriter
* object that later writes the data to the character
* output stream created for the specified abstract
* pathname file;
* Append2.java
* Author:-RoseIndia Team
* Date:-5-july-2008
*/
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
public class Append2 {
public static void main(String args[]) throws IOException {
File witches = new File("c:\Desktop\amrit.txt");
System.out.println(witches.createNewFile());
//"ASCII" is a predefined unicode characterset.
PrintWriter Dream = new PrintWriter(witches, "ASCII");
char [] array = {'M','a','t','r','i','x'};
char data[] = {'1', '2', '3'};
String str0 = new String(array);
String str1 = new String(data);
//Dream.append(CharSequence csq)
//CharSequence is the collection of two or more char values.
Dream.append(str0);
Dream.append(" " + str1);
Dream.checkError();
}
} |
Output of the program:-
Result is generated on the specified abstract pathname file and not on the console
Matrix 123 |
|