Runtime.getRuntime()。exec不能与.swf一起使用

时间:2015-01-12 01:54:23

标签: java

我正在制作一个程序,当你点击一个按钮时启动一些程序。我已经运行.exe文件没有问题但是当我尝试运行.swf它给了我这个错误:

java.io.IOException: Cannot run program "C:\\blah\\blah\\blah\\realm.swf": CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at newbuttonthing.buttonthing$6.widgetSelected(buttonthing.java:152)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
    at newbuttonthing.buttonthing.open(buttonthing.java:48)
    at newbuttonthing.buttonthing.main(buttonthing.java:33)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 13 more

我正试图这样做:

Button Realm = new Button(shlStarter, SWT.NONE);
        Realm.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                try {
                    Runtime.getRuntime().exec(
                            "C:\\Users\\liam\\Desktop\\rotmg\\realm.swf");
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        });
        Realm.setText("Realm");
        Realm.setBounds(308, 50, 116, 25);

1 个答案:

答案 0 :(得分:1)

.swf文件不是可执行文件。双击.swf文件时,桌面管理器使用默认的swf文件注册程序并将此文件作为参数传递。您可以使用Windows START命令重新创建行为。所以试试......

Runtime.getRuntime().exec("start C:\\Users\\liam\\Desktop\\rotmg\\realm.swf");

或者正如Mad Progarammer所指出的那样:)

if (Desktop.isDesktopSupported()) {
    Desktop.getDesktop().open(new File("C:\\Users\\liam\\Desktop\\rotmg\\realm.swf"));
}