java.io.OutputStreamWriter
class connects byte streams and character streams: It writes bytes onto the underlying output stream after
translating characters according to a specified character encoding. The encoding can be set in the constructor, or you can accept the platform's default encoding.
public OutputStreamWriter(OutputStream out, String enc)
throws UnsupportedEncodingException
public OutputStreamWriter(OutputStream out)
For example, to attach an OutputStreamWriter
to System.out
with the default encoding, (generally ISO Latin-1):
OutputStreamWriter osw = new OutputStreamWriter(System.out);
On the other hand if you wanted to write a file encoded in the Macintosh Symbol font, you might do this:
FileOutputStream fos = new FileOutputStream("symbol.txt");
OutputStreamWriter osw = new OutputStreamWriter(fos, "MacSymbol");
public String getEncoding()
The getEncoding()
method returns a string containing
the name of the encoding used by this writer.
The other methods just override methods from java.io.Writer
, but behave
identically from the perspective of the programmer.
public void write(int c) throws IOException
public void write(char c[], int offset, int length) throws IOException
public void write(String s, int offset, int length) throws IOException
public void flush() throws IOException
public void close() throws IOException