Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java UTF-8无法正确地将日语字符(平假名和片假名)字符串作为参数传递_Java_Eclipse_Utf 8_Shift Jis - Fatal编程技术网

Java UTF-8无法正确地将日语字符(平假名和片假名)字符串作为参数传递

Java UTF-8无法正确地将日语字符(平假名和片假名)字符串作为参数传递,java,eclipse,utf-8,shift-jis,Java,Eclipse,Utf 8,Shift Jis,例如,我需要的文件在此文件路径中找到,它将作为参数传递: “C:\Users\user.name\docs\jap\あああいいいうううえええおおおダウンロード\filename.txt“ 我使用此代码解码字符: String new_path = new String(args[0].getBytes("Shift_JIS"), StandardCharsets.UTF_8); System.out.println(new_path); 然而,输出是: C:\Users\user.name\d

例如,我需要的文件在此文件路径中找到,它将作为参数传递:

“C:\Users\user.name\docs\jap\あああいいいうううえええおおおダウンロード\filename.txt“

我使用此代码解码字符:

String new_path = new String(args[0].getBytes("Shift_JIS"), StandardCharsets.UTF_8);
System.out.println(new_path);
然而,输出是:

C:\Users\user.name\docs\jap\あああい�?�?�?�?�?えええおおお�?ウンロード\filename.txt

有些字符没有被正确解码。我已经将控制台的文本编码和编码更改为UTF-8,但仍然不起作用

但如果我能定期打印,它的显示效果会很好

System.out.println("C:\\Users\\user.name\\docs\\jap\\あああいいいうううえええおおおダウンロード\\filename.txt");
其中显示:

C:\Users\user.name\docs\jap\あああいいいうううえええおおおダウンロード\filename.txt

请告诉我如何阅读其他字符,这真的是一个很大的帮助。谢谢

public static void main(String[] args) throws UnsupportedEncodingException {
    // it is your code
    String newPath = new String(args[0].getBytes("Shift_JIS"), StandardCharsets.UTF_8);
    System.out.println(newPath);
    // instead of your code
    newPath = args[0];
    System.out.println(newPath);
}
也许,你可以展示“あああいいいうううえええおおおダウンロード".


如果使用字节数组和相应的字符集创建字符串对象,则可以将其转换为任何字符集。

使用此
String path=“C:\\Users\\user.name\\docs\\jap\\あああいいいうううえええおおおダウンロード\filename.txt“String new_path=new String(path.getBytes(),StandardCharsets.UTF_8);
您告诉String.getBytes在“Shift_JIS”编码中提供字节,然后告诉字符串构造函数字节编码是UTF-8-这显然是错误的。您应该能够使用args[0]字符串直接打印而不进行任何转换。@suneel它应该作为参数传递,因此使用args[0]@greg-449我确实尝试过直接打印args[0]字符串,但是输出是:C:\Users\user.name\docs\jap\縺ゅ≠縺ゅ>縺�縺�縺�縺�縺�縺医∴縺医♀縺翫♀繝�繧ヲ繝ウ繝ュ繝シ繝噂filename.txtI尝试了您的代码,但它返回:C:\Users\user.name\docs\jap\縺ゅ≠縺ゅ>縺�縺�縺�縺�縺�縺医∴縺医♀縺翫♀繝�繧ヲ繝ウ繝ュ繝シ繝噂filename.txt我使用韩国windows。但我执行我的代码,E:\temp\縺ゅ≠縺ゅ>java UTF8PathTestあああいいいうううえええおおおダウンロード ???????????????????????????????_?Eあああいいいうううえええおおおダウンロ?ド您使用了Eclipse吗?如果是,您使用了什么编码?