代码里面执行bat

public static void executeBat(String path) {
        try {
            File file = new File(path);
            if (file.exists()) {
                String parentpath = file.getParent();
                parentpath = parentpath.replaceAll("\\", "/");
                String fname = file.getName();
                Runtime rntime = java.lang.Runtime.getRuntime();
                if (Common.WINDOWS) {
                    if (!fname.endsWith(".bat")) {
                        fname = fname.substring(0, fname.lastIndexOf("."))
                                + ".bat";
                    }
                    path = parentpath + "/" + fname;
                    Process process = rntime.exec("cmd /c start " + path);
                }
            }

        } catch (Exception e) {
        }

原文地址:https://www.cnblogs.com/o-andy-o/p/3449160.html