I am using SWT’s FileDialog to let user select several files:
FileDialog dlg = new FileDialog(s, SWT.MULTI);
dlg.setFilterPath(somePath);
String fn = dlg.open();
if (fn != null)
String [] files = dlg.getFileNames()
While fn returns the absolute path to the directory, the files array contains relative paths. I would like to get an absolute path for each file. Is there a way of doing this in Java that works across platforms (Win, Linux, MacOS)?
You need to append the filename to the given filter path. To avoid worrying about path separators and the like, you can just use the
Fileclass. For example:If you need the path as a
String, you can of course use thegetAbsolutePath()method on the resultantFiles.