I am now using java Desktop API to manipulate file explorer. I know how to open the file explorer but I don't know how to open it and highlight the specified file.
As we using the Chrome, after downloading files, we can choose "show in folder" to open the file explorer and highlight the downloaded file.
How to use java Desktop API to do so? Or is there any other API in java can realize this action?
Opening file explorer with java in any platform – Windows, Linux and Mac. The easiest way to do this is by using Java Desktop. The class provides an open() function Desktop#open(File) to open explorer when the given file is a directory. From Java 9 onwards, Desktop is available on the java.
Searching files in Java can be performed using the File class and FilenameFilter interface. The FilenameFilter interface is used to filter files from the list of files. This interface has a method boolean accept(File dir, String name) that is implemented to find the desired files from the list returned by the java. io.
Use a FileWriter object, and use the constructor that takes the File object and a boolean, the latter if true would allow appending text into the File if it exists. Then initialize a PrintWriter passing in the FileWriter into its constructor.
Use: Runtime.getRuntime().exec("explorer.exe /select," + path);
This also works if there is a space in the PATH
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With