apache commons vfs库似乎无法支持特殊的windows文件夹(network、recent、computer、libraries等)。
File[] cbFolders = (File[])sun.awt.shell.ShellFolder.get("fileChooserComboBoxFolders");
然后将它们转换为文件对象,如下所示:
for(File f: cbFolders){
fileObjArray.add(mgr.resolveFile(f.getPath()));
}
它只是不工作,你得到的只是它的名字的路径名。
这些文件的路径类似于
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
如果能帮上忙,我们将不胜感激。它看起来很可能是图书馆里的一个错误。希望有人知道一个黑客或类似的工作。
编辑:
我相信当我创造新的捷径时
try{
final File[] cbFolders = (File[])sun.awt.shell.ShellFolder.get("fileChooserComboBoxFolders");
String name = "";
File[] systemFiles = new File[cbFolders.length];
i =0;
for(File f: cbFolders){
name = f.getName();
if(name.startsWith("::{")){
name = name.substring(2);
System.out.println("converting: " + name);
String fileName = fileSystemView.getSystemDisplayName(f);
File file = new File("C:\\Users\\Daniel\\Desktop\\" + fileName + "." + name);
boolean success = false;
success = file.mkdir(); //returns false even if it works,
systemFiles[i] = file;
}else
systemFiles[i] = f;
i++;
}
list = new ArrayList<File>(Arrays.asList(systemFiles));
}catch(final Exception e){
...
}
它显示了正确的图标和名称,在windows资源管理器上它可以正确打开,但在vfs中它仍然会打开一个空文件夹。
最佳答案
对那些文件没有真正的支持。主要的问题是,Java文件对象既没有正确地对待它们(new File("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}").toURI().toString()
没有正确地转义冒号),也没有Java或VFS知道::是一个绝对的文件系统根。因此不能将它们转换为uri(resolvefile()所需),该uri保留windows可识别的特殊属性。