[英]get selected file path in windows explorer with Java
I'm developping a Java application in which the user is able to change the background of a JFrame using a picture from his computer. 我正在开发一个Java应用程序,用户可以在其中使用计算机上的图片来更改JFrame的背景。
In order to do that I'm trying to get the path name of the picture he selects in windows explorer. 为此,我试图获取他在Windows资源管理器中选择的图片的路径名。
I use this code to open the explorer but I can't figure out what I got to do next to get the selected file path... 我使用此代码打开资源管理器,但无法弄清楚下一步如何获取选定的文件路径...
p = new ProcessBuilder("explorer.exe", "/select,C:\\directory\\selectedFile").start();
Any ideas ? 有任何想法吗 ?
Thanks. 谢谢。
You should use a JFileChooser instead. 您应该改为使用JFileChooser 。
Then retrieve the selected file as a File
object using the getSelectedFile() method. 然后使用getSelectedFile()方法将所选文件作为File
对象检索。
更好的选择是JFileChooser,用于选择文件。
我建议使用JFileChooser 。
That may be possible, but it is much easier to use a JFileChooser . 这可能是可行的,但是使用JFileChooser会容易得多。 You can set the look and feel to mimic the current environment (Windows, in your case). 您可以设置外观以模仿当前环境(在您的情况下为Windows)。 I recommend googling JFileChooser as there are tons of examples (including in the API). 我推荐使用JFileChooser,因为有很多示例(包括API中的示例)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.