I have a Java application that receives data through a socket using InputStreamReader . It reports "Cp1252" using the getEncoding method:
Socket Sock = ...; InputStreamReader is = new InputStreamReader(Sock.getInputStream()); System.out.println("Character encoding = " + is.getEncoding());
This does not necessarily correspond to what the system reports as a code page. For example:
C: \> chcp
Active code page: 850
An application can accept byte 0x81, which on the code page 850 represents the ΓΌ character. The program interprets this byte with code page 1252, which does not define any character in this value, so I get a question mark.
I was able to work around this problem for one client that used code page 850 by adding another command line parameter in the batch file that launches the application:
java.exe -Dfile.encoding = Cp850 ...
But not all of my clients use code page 850, of course. How can I get Java to use a codepage compatible with the underlying Windows system? My preference would be that I could just paste into a batch file, leaving the Java code intact:
ENC = ...
java.exe -Dfile.encoding =% ENC% ...
java windows batch-file codepages
Rob kennedy
source share