开发者

Get the path of chosen file java

How to display a JFileChooser so I get the absolute path of a file, then assign the path to a string

开发者_如何学编程

I was doing something like:

JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);


You need to complete like:

int option = chooser.showOpenDialog(parentComponent); // parentComponent must a component like JFrame, JDialog...
if (option == JFileChooser.APPROVE_OPTION) {
   File selectedFile = chooser.getSelectedFile();
   String path = selectedFile.getAbsolutePath();
}


File f = chooser.getSelectedFile();
String absPath = f.getAbsolutePath();


File f = chooser.getSelectedFile();

String path = f.getAbsolutePath();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜