Nick Nick - 3 years ago 139
Java Question

How to get absolute path from FileDialog?

I'm creating FileDialog and trying to get a FilePath for FileDialog object.

FileDialog fd = new FileDialog(this, "Open", FileDialog.LOAD);
fd.setVisible(true);
String path = ?;
File f = new File(path);


In this codes, I need to get a absolute FilePath for using with File object.
How can I get filepath in this situation?

Answer Source

Check out File.getAbsolutePath():

String path = new File(fd.getFile()).getAbsolutePath();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download