Java Charset problem on linux

后端 未结 3 741
盖世英雄少女心
盖世英雄少女心 2021-02-14 04:57

problem: I have a string containing special characters which i convert to bytes and vice versa..the conversion works properly on windows but on linux the special character is no

3条回答
  •  再見小時候
    2021-02-14 05:26

    You should make the conversion explicitly:

    byte[] byteArray = "abcd".getBytes( "ISO-8859-1" );
    new String( byteArray, "ISO-8859-1" );
    

    EDIT:

    It seems that the problem is the encoding of your java file. If it works on windows, try compiling the source files on linux with javac -encondig ISO-8859-1. This should solve your problem.

提交回复
热议问题