java.io.OutputStreamWriter
java.io.Writer
java.io.FileWriter
None
New as of JDK 1.1
The OutputStreamWriter class is a bridge between the byte-oriented world of the OutputStream class and the character-oriented world of the Writer class. The OutputStreamWriter represents a character stream, but it sends its output to an underlying byte stream. A character encoding scheme is responsible for translating the Unicode characters to bytes. An OutputStreamWriter can be created using an explicit encoding scheme or a default encoding scheme.
For example, to write a Unicode character stream as an ISO-8859-5 byte stream, you can construct an OutputStreamWriter with the encoding 8859_5 as follows:
OutputStreamWriter outr = new OutputStreamWriter(out, "8859_5");
Each time you write to an OutputStreamWriter object, bytes may be written to the underlying byte stream. To improve efficiency, you may want to wrap the OutputStreamWriter in a BufferedWriter.
public class java.io.OutputStreamWriter extends java.io.Writer { // Constructors public OutputStreamWriter(OutputStream out); public OutputStreamWriter(OutputStream out, String enc); // Instance Methods public void close(); public void flush(); public String getEncoding(); public void write(int c); public void write(char[] cbuf, int off, int len); public void write(String str, int off, int len); }
The output stream to use.
This constructor creates an OutputStreamWriter that writes its data to out and translates characters to bytes using the system's default encoding scheme.
public OutputStreamWriter(OutputStream out, String enc) throws UnsupportedEncodingException
The output stream to use.
The name of an encoding scheme.
If enc is not a supported encoding scheme.
This constructor creates an OutputStreamWriter that writes its data to out and translates characters to bytes using the given encoding scheme.
If any kind of I/O error occurs.
Writer.close()
This method calls the close() method of the underlying output stream, which releases any system resources associated with this object.
If any kind of I/O error occurs.
Writer.flush()
This method writes out any buffered data in the internal buffer and calls the flush() method of the underlying output stream, which forces any bytes that may be buffered to be written to the underlying device.
A String that contains the name of the character encoding scheme of this writer.
This method returns the name of the character encoding scheme this OutputStreamWriter is currently using.
The value to write.
If any kind of I/O error occurs.
Writer.write(int)
This method converts the given character to bytes using the current encoding scheme and places the converted bytes into an internal buffer. When the buffer fills up, it is written to the underlying byte stream.
public void write(char[] cbuf, int off, int len) throws IOException
An array of characters to write.
An offset into the character array.
The number of characters to write.
If any kind of I/O error occurs.
Writer.write(char[], int, int)
This method converts len characters from the array cbuf to bytes, starting at offset off, using the current encoding scheme. The method places the converted bytes into an internal buffer. When the buffer fills up, it is written to the underlying byte stream.
The string to be written.
An offset into start in the string.
The number of characters to write.
If any kind of I/O error occurs.
Writer.write(String, int, int)
This method converts len characters from the string str to bytes, starting at offset off, using the current encoding scheme. The method places the converted bytes into an internal buffer. When the buffer fills up, it is written to the underlying byte stream.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
write(char[]) |
Writer |
write(String) |
Writer |
BufferedWriter, FileWriter, IOException, OutputStream, UnsupportedEncodingException, Writer
This HTML Help has been published using the chm2web software. |