Java:JFileChooser获取国际文件名 [英] Java: JFileChooser getting international filenames

查看:53
本文介绍了Java:JFileChooser获取国际文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JFileChooser并获取带有中文字符的文件名. JFileChooser可以正确显示它们,我希望能够捕获这些文件名并将它们显示给用户.

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.

我的文件名是:03玩爱之徒.mp3

I have filename: 03 玩愛之徒.mp3

但是我最终显示: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.

推荐答案

问题不在文件名中,而是在用于读取日志的字体中.如果要将日志定向到文件,请尝试在与Unicode兼容的编辑器中读取日志,并确保日志正在使用BufferedWriter或类似的类(用于写入文件/屏幕).

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

这篇关于Java:JFileChooser获取国际文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆