OutputStreamWriter getEncoding Example
OutputStreamWriter class getEncoding example. This example shows you how to use getEncoding method.
OutputStreamWriter class getEncoding example. public String getEncoding() Returns the name of the character encoding being used by this stream. If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned.
Here is the code
/**
* @ # GetEncoding.java
* A class repersenting use to GetEncoding method
* of OutputStreamWriter class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class GetEncoding {
public static void main(String args[]) throws Exception {
// Create a new instance of a OutputStreamWriter object
// attached to a ByteArrayOutputStream.
ByteArrayOutputStream out =
new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out);
// Write to the output stream.
String s = "Random bytes";
writer.write(s);
writer.flush();
// Display the contents of the ByteArrayOutputStream.
System.out.println(out.toString());
// Display the encoding being used.
System.out.println("encoding: " +
writer.getEncoding());
// Close the OutputStreamWriter object.
writer.close();
}
} |
Output
Random bytes
encoding: UTF8 |
|