Charset names in java.io and java.nio

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.io_OutputStreamWriter;
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top