开发者

Run a .dmg file through java code

开发者 https://www.devze.com 2023-04-09 14:40 出处:网络
How can I mount开发者_如何转开发 a .dmg file through java code under OS X?This will work (but only on OS X):

How can I mount开发者_如何转开发 a .dmg file through java code under OS X?


This will work (but only on OS X):

    try {
        String[] command = {"/usr/bin/hdiutil", "attach", "/Users/path/to/your.dmg"};
        String sendback = "";    
        Process proc = Runtime.getRuntime().exec(command);
        InputStream istr = proc.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(istr));
        String str;
        while ((str = br.readLine()) != null) {
            sendback = sendback + str;
        }
        int resultCode = proc.waitFor();
        br.close();
        if (resultCode != 0) {
            throw new Exception("failed to open system profiler");
        }
    }
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


DMGs are not executables, are apple diskimages

reference is here

thus you can't "run" it.


You can use a Process, of course. But it won't work anywhere except on a Mac.


Saying that is like asking how to run an ISO file through Java. You simply can't; it's a disk image.

0

精彩评论

暂无评论...
验证码 换一张
取 消