Briefly about issue:
I have a file "лл.txt". When I read it's name into String it become "%D0%BB%D0%BB.txt". Then if I want to open and read that file it fails to find it
// filename contains "%D0%BB%D0%BB.txt"
in = new BufferedReader(new FileReader(new File(filename))); // File not found
but it perfectly works if I give the original name
in = new BufferedReader(new FileReader(new File("лл.txt"))); // ok
so the question is ho to get "лл.txt" from "%D0%BB%D0%BB.txt" ? a quick search led me to this
byte[] bytes = str.getBytes( Charset.forName("UTF-8" ));
str = new String( bytes, Charset.forName("UTF-8") );
but it doesn't work for me
It looks to be URL encoded with utf-8 charset. You can take cue from the following sample conversion:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.