我在制作一个搜索文件的程序,搜索后符合条件的文件都将显示在JTable里,我希望当我点击文件名
时能用被关联的软件来打开文件;
java能做到这一点吗?

解决方案 »

  1.   

    在Windows下可以试试Runtime.exec( "start " + filename );
      

  2.   

    >在Windows下可以试试Runtime.exec( "start " + filename );filename的类是File吗
      

  3.   

    我试过了,不行
    import java.io.File;
    import java.io.IOException;
    public class TestOpen{
        public static void main(String[] args) throws IOException{
            String f="G:/JBuilder/builder/copyrights.html";
            Runtime r = Runtime.getRuntime();
            r.exec("start "+f);
        }
    }
      

  4.   

    import java.io.File;
    import java.io.IOException;
    public class TestOpen{
        public static void main(String[] args) throws IOException{
            String f="G:/JBuilder/builder/copyrights.html";        Runtime r = Runtime.getRuntime();
            r.exec("start "+f);
        }
    }
      

  5.   

    没有写完恢复出去了,不好意思,下面这个程序可以
    import java.io.File;
    import java.io.IOException;
    public class TestOpen{
        public static void main(String[] args) throws IOException{
            String f="G:/JBuilder/builder/copyrights.html";
            try{
            Runtime r = Runtime.getRuntime();
            r.exec("cmd /c start " + f);
              }catch(Exception e)
             {         }
        }
    }
      

  6.   

    public class RunTimeTest{
        public static void main(String[] args) throws Exception{
            String f="your file path name";
            Runtime r = Runtime.getRuntime();
            r.exec("cmd /c start " + f);
        }
    }