Java: JFileChooser getting international filenames
I am using JFileChooser and getting file names with Chinese characters in them. JFileChooser displays them 开发者_运维问答properly, and I want to be able to capture these file names and display them back to the user.
I have filename: 03 玩愛之徒.mp3
But I end up displaying: 03 ????.mp3
In my code I get...
File f1 = fileChooser.getSelectedFile();
log("f1="+ f1.getName()); // gets me 03 ????.mp3
byte[] fname1 = f1.getName().getBytes(); // gets me [B@3f72c47b
byte[] fname2 = f1.getName().getBytes("UTF-16"); // gets me [B@411b1d80
I know I am close, but am needing a little help.
The issue is not in the file name, but in the fonts which are being used to read the logs. If you are directing the logs to a file, try reading it in a unicode compatible editor, Also make sure that log is using BufferedWriter or similar class (for writing to file/screen).
精彩评论