开发者

Get the path of chosen file java

开发者 https://www.devze.com 2023-02-22 12:56 出处:网络
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:

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

精彩评论

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