比如说通过双击打开word~ 在java中如何做到呢~

解决方案 »

  1.   

    Runtime.getRuntime().exec(String cmd)能做到等价于你在开始->运行里输入的命令。
    比如
    Runtime.getRuntime().exec("cmd.exe /c start http://www.csdn.net");
    将打开IE,然后连到csdn至于你说的用打开word,可以具体研究在命令行里怎么完成这种功能的,比如"可执行文件路径"+ "参数"
      

  2.   

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;import javax.swing.*;public class OpenIE extends JFrame { public OpenIE() {
    JButton button = new JButton("Open");
    button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    try {
    /* String[] strs = {"C:\\Program Files\\Internet Explorer\\iexplore.exe", 
    "http://dzh.mop.com/topic/readSub_5661107_0_0.html"};*/
    String[] strs = {"C:\\Program Files\\Microsoft Office\\Office10\\WINWORD.exe", "D:\\Develop Documents\\XML实用大全.doc"};
    Runtime.getRuntime().exec(strs);
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    }

    });

    this.getContentPane().add(button);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setBounds(200, 200, 200, 200);
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new OpenIE().setVisible(true);
    }}