在 SWT 中打开多个文件的一种方法是使用 FileDialog:
FileDialog dialog = new FileDialog(shell, SWT.MULTI);
dialog.open();
System.out.println(dialog.getFilterPath());
System.out.println(Arrays.toString(dialog.getFileNames()));
并且每个文件名都可以与过滤器路径连接。
这有效,除非文件位于对话框中“最近使用”或“搜索”(GTK 版本)中给出的不同文件夹中。过滤器路径最终仅对某些文件是正确的。
例如,如果路径是:
/path1/file1
/path2/file2
filterPath 是 'path1',而 fileNames 是 [file1, file2],所以缺少 'path2'。
在这种情况下,有没有办法获得正确的路径,或者 SWT 中的任何替代方法?