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?
fd.getFile();
– Triplicatefd.setDirectory("C://");
and treat all paths you get as relative to that. – TriplicateFile f = fd.getFiles()[0];
but check the array is not of 0 length (meaning no file selected) before doing that. 2) Why use AWT? See this answer for many good reasons to abandon AWT components in favor of Swing. – Redwine