![]() |
VOOZH | about |
In Java, OutputStreamWriter class connects character streams to byte streams. It encodes Characters into bytes using a specified charset.
public class OutputStreamWriter
extends Writer
Constructors in OutputStreamWriter are mentioned below:
Method | Description |
|---|---|
| flush() | flushes the stream |
| close() | closes the flushed stream |
| write(int char) | writes a single character. |
| write(String geek, int offset, int strlen) | writes a portion of the "geek" string starting from "offset position" upto "strlen" length. |
| write(char[] geek, int offset, int strlen) | writes a portion of the "geek" character array starting from "offset position" upto "strlen" length. |
| getEncoding() | tells the name of the character encoding being used in the mentioned Stream. |
java.io.OutputStreamWriter.flush() flushes the stream.
Syntax : public void flush()
Parameters :
------
Return :
void
Exception :
-> IOException : if in case anu I/O error occurs.
java.io.OutputStreamWriter.close() closes the flushed stream.
Syntax : public void close()
Parameters :
------
Return :
void
Exception :
-> IOException : if in case anu I/O error occurs, e.g writing after closing the stream
java.io.OutputStreamWriter.write(int char) writes a single character.
Syntax : public void write(int char)
Parameters :
char : character to be written
Return :
void
Example:
Output :
write(int char) : G
write(int char) : E
write(int char) : E
write(int char) : K
write(int char) : S
java.io.OutputStreamWriter.write(String geek, int offset, int strlen) writes a portion of the "geek" string starting from "offset position" upto "strlen" length.
Syntax :public void write(String geek, int offset, int strlen)
Parameters :
geek : string whose portion is to be written
offset : starting position from where to write
strlen : length upto which we need to write
Return :
void
Exception :
-> IOException : if in case any I/O error occurs.
Example:
Output :
write(int char) : S
write(int char) : F
write(int char) : o
write(int char) : r
write(int char) : G
java.io.OutputStreamWriter.write(char[] geek, int offset, int strlen) writes a portion of the "geek" character array starting from "offset position" upto "strlen" length.
Syntax : public void write(char[] geek, int offset, int strlen)
Parameters :
geek : character array whose portion is to be written
offset : starting position from where to write
strlen : length upto which we need to write
Return :
void
Exception :
-> IOException : if in case anu I/O error occurs.
java.io.OutputStreamWriter.getEncoding() tells the name of the character encoding being used in the mentioned Stream.
If there is predefined name exists, then it is returned otherwise the canonical name of the encoding is returned.
Returns Null, if the stream has been already closed.
Syntax : public String getEncoding()
Parameters :
------
Return :
Name of the charset encoding used
Exception :
-> IOException : if in case anu I/O error occurs.
Output :
char[] geek, int offset, int strlen) : G
char[] geek, int offset, int strlen) : E
char[] geek, int offset, int strlen) : E
Name of the charset : UTF8