中文编码问题同时列出文件 [英] Chinese encoding issue while listing files

查看:124
本文介绍了中文编码问题同时列出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用中文 c $ c>的 Solaris10上运行Java应用程序。现在有一些中文文件名目录下的文件。当我做 files = new File(dir).list()其中dir是包含该中文文件的父目录,我得到结果文件名文件[0] as ????? (某些垃圾字符)。

I am running a Java application on a Solaris10 with Chinese. Now there are some files in a directory with chinese filenames. When I do files = new File(dir).list() where "dir" is the parent directory containing that chinese file, I get the result filename files[0] as ?????(some junk characters).

我的程序 file.encoding 属性已经设置为 GBK ,我也做 Charset.isSupported(GBK)它也返回true。那么哪里可能是问题。我没有想法。

Now the deal is that my programs file.encoding property is already set to GBK and I also do Charset.isSupported("GBK") and it returns true too. So where could be the problem. I am running out of ideas.

注意:我不会在任何地方打印文件或复制文件。我只是打开一个流,如下所示:

NOTE: I am not trying to print the filename anywhere or copy the file or something. I am simply openeing a stream to it, something like below:

files = new File(dir).list();
new FileInputStream(files[0]);

现在这给了我一个FileNotFoundExcpetion,所以我调试只是找到文件[0]内的值

Now this gives me a FileNotFoundExcpetion, so I debug just to find that value inside files[0] is "??????".

推荐答案

不知道这是做的好习惯。
尝试在启动jvm时设置字符集:java -Dfile.encoding =...

Not sure if it a good practice of doing it . try setting the charset when you launch the jvm using : java -Dfile.encoding="" ...

这篇关于中文编码问题同时列出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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