qq_36414401
2017-03-16 11:04
采纳率: 100%
浏览 1.4k
已采纳

win 10 cmd 控制台 为何无打印

import java.io.*;

public class ProcessDemo
{

public ProcessDemo()
{
}

public static void main(String args[])
    throws Exception
{
    String s = "System.out.println(\"zzzzzyyyy\")";
    eval(s);
}

private static void eval(String s)
    throws Exception
{
    StringBuilder stringbuilder = new StringBuilder(80);
    stringbuilder.append("public class Hello{");
    stringbuilder.append("public static void main(String[] args){");
    stringbuilder.append(s).append(";");
    stringbuilder.append("}");
    stringbuilder.append("}");
    FileOutputStream fileoutputstream = new FileOutputStream("Hello.java");
    fileoutputstream.write(stringbuilder.toString().getBytes());
    fileoutputstream.close();
    Process process = Runtime.getRuntime().exec("javac Hello.java");
    InputStream inputstream = process.getErrorStream();
    byte abyte0[] = new byte[1024];
    for (int i = -1; (i = inputstream.read(abyte0)) != -1;)
    {
        String s1 = new String(abyte0, 0, i);
        System.out.println(s1);
    }

    inputstream.close();

    Process process1 = Runtime.getRuntime().exec("java Hello");
    InputStream inputstream1 = process1.getErrorStream();
    int j;
    while ((j = inputstream1.read(abyte0)) != -1) 
    {
        String s2 = new String(abyte0, 0, j);
        System.out.println(s2);
    }
    inputstream1.close();
}

}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qq_36414401 2017-03-16 11:09
    已采纳

    我是直接在cmd里 运行后 有Hello 的字节码 控制台没有报错 就是无打印

    点赞 评论
  • qq_36414401 2017-03-16 11:10

    直接在 cmd 里 编译 运行 ProcessDemo程序

    点赞 评论

相关推荐 更多相似问题