Java 如何改变';字符集';在爪哇?

Java 如何改变';字符集';在爪哇?,java,character,Java,Character,大多数韩国人使用视窗操作系统。Window的韩文字符集是“EUC-KR”。因此,当mac os x用户使用Windows用户制作的文件时,他们必须使用一些网站将其字符更改为unicode,或者必须使用提供将字符更改为unicode功能的程序。现在我正在制作一些在MacOSX上使用文本数据文件的程序。因此,我想为我的程序提供将字符集更改为unicode的函数。如何在java中将“EUC-KR”字符更改为unicode“UTF-8”?尝试commons io函数IOUtils.toString(In

大多数韩国人使用视窗操作系统。Window的韩文字符集是“EUC-KR”。因此,当mac os x用户使用Windows用户制作的文件时,他们必须使用一些网站将其字符更改为unicode,或者必须使用提供将字符更改为unicode功能的程序。现在我正在制作一些在MacOSX上使用文本数据文件的程序。因此,我想为我的程序提供将字符集更改为unicode的函数。如何在java中将“EUC-KR”字符更改为unicode“UTF-8”?

尝试commons io函数IOUtils.toString(InputStream,String)


该工具也可以帮助实现这一点。

尝试commons io函数IOUtils.toString(InputStream,String)

该工具也可以帮助完成此操作。

尝试以下操作:

System.setProperty("file.encoding", "UTF-8");

public static String getDefaultCharEncoding(){
        byte [] bArray = {'w'};
        InputStream is = new ByteArrayInputStream(bArray);
        InputStreamReader reader = new InputStreamReader(is);
        String defaultCharacterEncoding = reader.getEncoding();
        return defaultCharacterEncoding;
    }
阅读更多信息:

尝试以下内容:

System.setProperty("file.encoding", "UTF-8");

public static String getDefaultCharEncoding(){
        byte [] bArray = {'w'};
        InputStream is = new ByteArrayInputStream(bArray);
        InputStreamReader reader = new InputStreamReader(is);
        String defaultCharacterEncoding = reader.getEncoding();
        return defaultCharacterEncoding;
    }
阅读更多信息:

我使用
InputStreamReader(Runtime.getRuntime().exec(“iconv-f EUC-KR-t UTF-8”+file.getPath()).getInputStream())InputStreamReader(Runtime.getRuntime().exec(“iconv-f EUC-KR-t UTF-8”+file.getPath()).getInputStream())并且它工作正常。