简体   繁体   English

使用Java在Windows资源管理器中获取选定的文件路径

[英]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.

相关问题 Android - 获取从文件资源管理器中选择的 .txt 文件的真实路径 - Android - Get real path of a .txt file selected from the file explorer 如何使用Java从Windows文件资源管理器返回文件路径 - How to return the file path from the windows file explorer using Java 使用JNA在Windows资源管理器中获取选定的文件项 - Get selected file item in Windows Explorer using JNA 如何在Java中的Windows资源管理器中获取文件右键菜单 - How to get the file right click menu in windows explorer in Java Java在Windows资源管理器中选择文件? - Java Select File in windows Explorer? 我想从包资源管理器中检索所选Java文件的路径/文件名 - I want to retrieve the path/filename of the selected java file from the package explorer Java Web Application:如何获取所选文件的原始路径? - Java Web Application:how to get the original path of selected file? 尝试从 windows 资源管理器打开 a.java 文件时,我收到“找不到可打开文件的项目”错误消息 - When trying to open a .java file from windows explorer I get a “No project found to open file in” error message 获取没有驱动器号的文件路径 - Windows 10 / Java 8 - Get path of file without drive letter - Windows 10 / Java 8 在Windows 7上:相同的路径,但Explorer和Java看到的文件不同于Powershell - On Windows 7: Same path but Explorer & Java see different files than Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM