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

前端 未结 3 2095
抹茶落季
抹茶落季 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:46

    import java.awt.Desktop;
    import java.io.File;
    
    public class OpenAppData {
    
        public static void main(String[] args) throws Exception {
            // Horribly platform specific.
            String appData = System.getenv("APPDATA");
            File appDataDir = new File(appData);
            // Get a sub-directory named 'texture'
            File textureDir = new File(appDataDir, "texture");
            Desktop.getDesktop().open(textureDir);
        }
    }
    

提交回复
热议问题