使用JFileChooser获取目录的路径 [英] Get the path of a directory using JFileChooser

查看:289
本文介绍了使用JFileChooser获取目录的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JFileChooser获取目录的绝对路径,只需选择目录?

How can I get the absolute path of a directory using JFileChooser, just selecting the directory?

推荐答案

使用:

chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//or
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

以及:

chooser.getCurrentDirectory()
//or
chooser.getSelectedFile();

然后在<上打 getAbsoluteFile() code>文件返回对象。

then call getAbsoluteFile() on the File object returned.

这篇关于使用JFileChooser获取目录的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆