How to make a button that, when clicked, opens the %appdata% directory?

前端 未结 3 2089
抹茶落季
抹茶落季 2020-12-20 03:25

I have made a button, but I don\'t now how to make it open a specific directory like %appdata% when the button is clicked on.

Here is the code ->

3条回答
  •  长情又很酷
    2020-12-20 03:54

    Execute a command using Runtime.exec(..). However, not every OS has the same file explorer, so you need to handle the OS.

    Windows: Explorer /select, file

    Mac: open -R file

    Linux: xdg-open file

    I wrote a FileExplorer class for the purpose of revealing files in the native file explorer, but you'll need to edit it to detect operating system. http://textu.be/6

    NOTE: This is if you wish to reveal individual files. To reveal directories, Desktop#open(File) is far simpler, as posted by Andrew Thompson.

提交回复
热议问题