我的eclipse上有一个项目,其中一个方法是从文件夹中读取文件列表。 当我从日食或从出口的罐子里运行时,它很好并且效果很好。
但我在我的netbeans上有另一个项目用于此应用程序的GUI,其中包含导出的jar(工作正常)但是当我从netbeans运行或导出此项目时,它只能读取非英文文件名,其转换文件名是这样的
???????? ???? ??? .mp3
我尝试将-J-Dfile.encoding=UTF-8
添加到netbeans.conf
我也尝试在netbeans项目属性中选择编码,但没有运气。
这里有一些代码:
public SFile(String path, FileFilter filter) {
File f = null;
f = new File(path);
directory = f.isDirectory();
if (directory) {
children = new ArrayList<SFile>();
File[] ki = f.listFiles(filter); // here i see the ???? ????.mp3
ArrayList<File> kids = new ArrayList<File>();
Collections.addAll(kids, ki);
Collections.sort(kids, comparator);
for (File k : kids) {
if (k.isDirectory() && k.listFiles(filter).length == 0) {
continue;
}
children.add(new SFile(k.getAbsolutePath(), filter));
}
} else {
// some more code...
}
}
过滤器代码:
new FileFilter() {
public boolean accept(final File pathname) {
try {
return pathname.getCanonicalPath().endsWith(".mp3") || pathname.isDirectory();
} catch (final IOException e) {
e.printStackTrace();
}
return false;
}
};
我的项目依赖项:
/Users/dima/Dev/RSLib/asm-3.1.jar
/Users/dima/Dev/RSLib/grizzly-framework-2.2.16.jar
/Users/dima/Dev/RSLib/grizzly-http-2.2.16.jar
/Users/dima/Dev/RSLib/grizzly-http-server-2.2.16.jar
/Users/dima/Dev/RSLib/grizzly-rcm-2.2.16.jar
/Users/dima/Dev/RSLib/gson-2.2.2.jar
/Users/dima/Dev/RSLib/javax.servlet-api-3.1-b05.jar
/Users/dima/Dev/RSLib/jersey-bundle-1.16.jar
/Users/dima/Dev/RSLib/jersey-core-1.16.jar
/Users/dima/Dev/RSLib/jersey-grizzly2-1.16.jar
/Users/dima/Dev/RSLib/jersey-server-1.16.jar
/Users/dima/Dev/RSLib/jsr311-api-1.1.1.jar
/Users/dima/Dev/RSLib/log4j-1.2.17.jar
/Users/dima/Dev/RSLib/jid3lib-0.5.4.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/cling-mediarenderer-2.0-alpha2-standalone.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/cling-workbench-2.0-alpha2-standalone.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/seamless-http-1.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/seamless-util-1.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/seamless-xml-1.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/support/cling-support-2.0-alpha2.jar
/Users/dima/Dev/RSLib/cling-distribution-2.0-alpha2/core/cling-core-2.0-alpha2.jar
/Users/dima/Dev/RSLib/MpegAudioSPI1.9.5/mp3spi1.9.5.jar
/Users/dima/Dev/RSLib/MpegAudioSPI1.9.5/lib/jl1.0.1.jar
/Users/dima/Dev/RSLib/MpegAudioSPI1.9.5/lib/tritonus_share.jar
答案 0 :(得分:1)
如果您使用的是java 7 listFiles
在Mac OS X上报告已损坏 - 请参阅here并在那里链接。如果更新无法修复,则应考虑moving to nio - 或查看here
我想看看你在listFiles(filter);