简要问题:
我有一个文件“лл.txt”。当我把它的名字读成字符串时,它变成“%D0%BB%D0%BB.txt”。然后,如果我想打开并阅读该文件,则无法找到它
// filename contains "%D0%BB%D0%BB.txt"
in = new BufferedReader(new FileReader(new File(filename))); // File not found
但如果我提供原始名称
,它就完美无缺in = new BufferedReader(new FileReader(new File("лл.txt"))); // ok
所以问题是从“%D0%BB%D0%BB.txt”获得“лл.txt”? 快速搜索让我看到了这个
byte[] bytes = str.getBytes( Charset.forName("UTF-8" ));
str = new String( bytes, Charset.forName("UTF-8") );
但它对我不起作用
答案 0 :(得分:0)
它看起来是用utf-8字符集编码的URL。您可以从以下示例转换中获取提示:
System.out.println(URLEncoder.encode("лл.txt", "utf-8")); // Gives %D0%BB%D0%BB.txt
System.out.println(URLDecoder.decode("%D0%BB%D0%BB.txt", "utf-8")); // Gives лл.txt