FileWriter is a subclass of OutputStreamWriter. The OutputStreamWriter stream converts characters written to it to bytes: OutputStreamWriter can be wrapped around any byte OutputStream, including File-OutputStream.FileWriter is actually a convenience class that is equivalent to an OutputStreamWriter stream wrapped around a FileOutputStream. So the statement in line 12 of WriteFile,
FileWriter out = new FileWriter("File1.txt");
is equivalent to
FileOutputStream fout = new FileOutputStream(''File1.txt");
OutputStreamWriter out = new OutputStreamWriter(fout);
Characters written to an OutputStreamWriter are converted to bytes using a character encoding scheme. The default is the host's default encoding scheme. For Windows, this is ISO 8859–1, the ISO Latin alphabet No. 1. To use another encoding scheme, it has to be specified in the second form of the OutputStreamWriter constructor. For example, if
we want to specify the ISO 8859-7 Latin/Greek alphabet, we would use the constructor
OutputStreamWriter out = new
OutputStreamWriter(fout, "ISO8859_7");
The OutputStreamWriter Stream in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment