Launch file from Java

帅比萌擦擦* 提交于 2019-12-01 03:47:40
Joonas Pulakka

Use Java Desktop API.

Desktop.getDesktop().open(new File(yourfilename));

If you're running 1.6, use the Desktop API per mad-j's advice. If you're using an older VM (1.5 or earlier) you'll need to write your own platform-specific code to do this.

On the mac,

Runtime.getRuntime().exec(new String[] {"open", pathToFile});

On windows,

Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", pathToFile});

You may need to escape the path on windows.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!