Java: JFileChooser getting international filenames

痴心易碎 提交于 2019-12-24 00:40:00

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/7477610/java-jfilechooser-getting-international-filenames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!