我如何在使用Java的euc-kr编码系统中读取utf8编码的文件名?

问题描述 投票:1回答:1

我使用euc-kr编码系统。我的程序是用Java编写的。读取文件名。但是程序无法读取某些文件名。(某些文件名称是utf8编码)

所以我尝试了这个

File dir = new File(dirPath);
File[] fileList = dir.listFiles(); //get files that file name is utf8 encoding
String cangedEncodingstr= new String(fileList[0].getName().getBytes("euc-kr"), "euc-kr"); // This is still an invalid string

我认为此字符串在调用dir.listFiles()期间已被破坏>

File dir = new File(dirPath);
File[] fileList = dir.listFiles(); //get files that file name is utf8 encoding

fileList[0].getName(); // broken String
fileList[0].isFile(); //false
fileList[0].isDirectory(); //false

utf8编码的字符串还期望isFile ()为true。

谢谢您的答复。 :-)

我使用euc-kr编码系统。我的程序是用Java编写的。读取文件名。但是程序无法读取某些文件名。 (某些文件名是utf8编码),所以我尝试了这个File dir = new File(dirPath)...

java encoding utf-8
1个回答
0
投票

File.getName()返回File.getName()。因此,您无需使用Java进行任何其他操作。

© www.soinside.com 2019 - 2024. All rights reserved.