开发者

International JRE6 or JDK6 or reading a file in "cp037" encoding scheme

开发者 https://www.devze.com 2022-12-31 06:05 出处:网络
I have been trying to read a file in \"cp037\" encoding scheme using JAVA. I able to read a file in ba开发者_如何学Gosic encoding schemes like UTF-8, UTF16 etc...After a bit of research on the interne

I have been trying to read a file in "cp037" encoding scheme using JAVA. I able to read a file in ba开发者_如何学Gosic encoding schemes like UTF-8, UTF16 etc...After a bit of research on the internet i came to know that we need charset.jar or international version of JRE be installed to support extended encoding schemes. Can anyone send me a link for international version of JRE6 or JDK6. or is there any better way that i could read a file in cp037 encoding scheme.

P.S: cp037 is a character encoding scheme supported by IBM Mainframes. All i need is to display a file in windows, which is being generated on IBM Mainframes machine, using a java program.

Thanks in advance for your help... :-)


I found this webpage for Java 5 (note, it might be different for Java 6). There is no special, separate "international" version of the JRE or JDK; however, the lib\charsets.jar may or may not be installed on your system depending on what your operating system supports.

Are you sure there is no charsets.jar in your JRE installation directory? On my system, it's under %JDK_HOME%\jre\lib. (Note: NOT under %JDK_HOME%\lib).

Search your system to see if you already have charsets.jar somewhere. (Note that it's called charsets.jar with an s, not charset.jar).


After a bit of research on the internet i came to know that we need charset.jar or international version of JRE be installed to support extended encoding schemes.

Are you sure that this charset isn't included in the standard distribution though?

This code works fine for me on jdk 1.6.0_17 64bit (Windows):

Charset charset = Charset.forName("cp037");
BufferedReader br = new BufferedReader(new InputStreamReader(
    new FileInputStream(f), charset));

String line = null;
while ((line = br.readLine()) != null) {
    System.out.println("read line: " + line);
}


As Reddy says sometimes the charsets.jar is there, however, the issue still exists.

The only solution I found was to add the jar to the jre system libraries using the buildpath funcionality of eclipse.

The change was done to the default windows java version.

A different option would be to instal jdk instead of jre.

Some info links about the java encode schemes:

http://www.oracle.com/technetwork/java/javase/readme-142177.html

http://download.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html


Here is a slightly different code with Java 1.6 on WinXP getting text from Mainframe over the web upload:

String text = new String(data, 0, data.length, "Cp037");
text = text.replace('', 'a');
text = text.replace('Ý', '[');
text = text.replace('¨', ']');

Note, that there are several characters, which need special attention.

0

精彩评论

暂无评论...
验证码 换一张
取 消