V
Vincenzo.Zocca
Hi guys,
Why is character set Cp1047 known in java.io but not in
java.nio.charset.Charset?
Enclosed nio and io examples illustrate what I mean.
Cheers,
Vince
NIO EXAMPLE
public class NioTest {
public static void main( String[] args) throws Exception {
java.nio.charset.Charset.forName("Cp1047");
}
}
COMMENTS
An exception is thrown:
Exception in thread "main"
java.nio.charset.UnsupportedCharsetException: Cp1047
at java.nio.charset.Charset.forName(Charset.java:486)
at NioTest.main(NioTest.java:3)
IO EXAMPLE
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.iutputStreamWriter;
public class IoTest {
public static void main( String[] args) throws Exception {
FileInputStream fis = new FileInputStream("/tmp/test.cp1047");
InputStreamReader ir = new InputStreamReader(fis, "Cp1047");
OutputStreamWriter osw = new OutputStreamWriter(System.out);
for (int c = ir.read(); c >= 0; c = ir.read())
osw.write(c);
osw.flush();
}
}
COMMENTS
Characters are read from file "/tmp/test.cp1047" which is in Cp1047
format.
The characters are then correctly written to System.out.
JAVA VERSION
$ java -version
java version "1.4.2-01"
Java(TM) 2 Runtime Environment, Standard Edition (build
Blackdown-1.4.2-01)
Java HotSpot(TM) Client VM (build Blackdown-1.4.2-01, mixed mode)
OPERATING SYSTEM
Vanilla Fedora Core 3
Why is character set Cp1047 known in java.io but not in
java.nio.charset.Charset?
Enclosed nio and io examples illustrate what I mean.
Cheers,
Vince
NIO EXAMPLE
public class NioTest {
public static void main( String[] args) throws Exception {
java.nio.charset.Charset.forName("Cp1047");
}
}
COMMENTS
An exception is thrown:
Exception in thread "main"
java.nio.charset.UnsupportedCharsetException: Cp1047
at java.nio.charset.Charset.forName(Charset.java:486)
at NioTest.main(NioTest.java:3)
IO EXAMPLE
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.iutputStreamWriter;
public class IoTest {
public static void main( String[] args) throws Exception {
FileInputStream fis = new FileInputStream("/tmp/test.cp1047");
InputStreamReader ir = new InputStreamReader(fis, "Cp1047");
OutputStreamWriter osw = new OutputStreamWriter(System.out);
for (int c = ir.read(); c >= 0; c = ir.read())
osw.write(c);
osw.flush();
}
}
COMMENTS
Characters are read from file "/tmp/test.cp1047" which is in Cp1047
format.
The characters are then correctly written to System.out.
JAVA VERSION
$ java -version
java version "1.4.2-01"
Java(TM) 2 Runtime Environment, Standard Edition (build
Blackdown-1.4.2-01)
Java HotSpot(TM) Client VM (build Blackdown-1.4.2-01, mixed mode)
OPERATING SYSTEM
Vanilla Fedora Core 3