How to use java code to open Windows file explorer and highlight the specified file?

Charles Wu picture Charles Wu · Sep 9, 2011 · Viewed 71.5k times · Source

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?

Answer

Stone picture Stone · Sep 8, 2014

Use: Runtime.getRuntime().exec("explorer.exe /select," + path);

This also works if there is a space in the PATH.