gpt4 book ai didi

java - 让特殊文件夹在 Apache Commons VFS 中工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:18:03 33 4
gpt4 key购买 nike

Apache Commons VFS 库似乎无法支持特殊的 Windows 文件夹(网络、最近、计算机、库等)。

File[] cbFolders = (File[])sun.awt.shell.ShellFolder.get("fileChooserComboBoxFolders");

然后像这样将它们转换为 FileObjects:

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 File 对象都没有正确对待它们(new File("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}").toURI().toString() 没有正确转义冒号)Java 或 VFS 也不知道::作为绝对文件系统根。因此,您不能将它们转换为 URI(resolveFile() 需要)来保留 Windows 识别的特殊属性。

关于java - 让特殊文件夹在 Apache Commons VFS 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4264142/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com