【发布时间】:2019-04-19 07:17:46
【问题描述】:
我使用 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 () 为真。
提前感谢您的回复。 :-)
【问题讨论】: