Runtime.getRuntime().exec("name.bat);

解决方案 »

  1.   

    java运行.bat文件需要运行cmd它产生的数据流会堵塞通道,所以要运行它必须将这个流读走。
    给你一个代码,可以解决这个问题。
    Process ps = Runtime.getRuntime().exec("E:\\test.bat"); 
    System.out.println(loadStream(ps.getInputStream())); //load the stream
    System.out.println(loadStream(ps.getErrorStream()));//load the stream
    //下面是读数据流的方法
    static String loadStream(InputStream in) throws IOException
        {
            int ptr = 0;
            in = new BufferedInputStream(in);
            StringBuffer buffer = new StringBuffer();
            while( (ptr = in.read()) != -1 )
            {
                buffer.append((char)ptr);
            }
            return buffer.toString();
        }这样应该可以了