简体   繁体   中英

Character encoding between Java (Linux) and Windows system

I have a simple program that makes a request to a remote server running a service which I believe is written in Delphi, but definately running on Windows.

I'm told the service will be using whatever the default encoding is for Windows.

When I get a response and use println to output it I'm getting some strange symbols in the output, which make me think it is a character encoding issue.

How can I tell Java the the input from the remote system is in the windows encoding?

I have tried the following:

_receive = new BufferedReader(new InputStreamReader(_socket.getInputStream(),"ISO-8859-1"));
_System.out.println(_receive.readLine());

The extra characters appear as squares in the output with 4 numbers in the square.

Unless you KNOW what the "default encoding" is, you can't tell what it is. The "default encoding" is generally the system-global codepage, which can be different on different systems.

You should really try to make people use an encoding that both sides agree on; nowadays, this should almost always be UTF-16 or UTF-8.

Btw, if you are sending one character on the Windows box, and you receive multiple "strange symbols" on the Java box, there's a good chance that the Windows box is already sending UTF-8.

使用cp1252代替ISO-8859-1 ,因为Windows上是默认设置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM