A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

本帖最后由 真实姓名被注册 于 2015-7-20 14:36 编辑

  1. <P>import java.util.*;
  2. import java.io.*;
  3. public class Temp{
  4. public static void main(String[] args){
  5. System.out.println("执行Temp");
  6. File file=new File("hehe.txt");
  7. try {
  8. System.setOut(new PrintStream(
  9. new BufferedOutputStream(
  10. new FileOutputStream("hehe.txt"))));
  11. } catch (FileNotFoundException e) {
  12. // TODO Auto-generated catch block
  13. e.printStackTrace();
  14. }
  15. System.out.println("abc");
  16. System.out.flush();
  17. }
  18. }
  19. import java.io.*;
  20. public class Test{
  21. public static void command(String command){
  22. try{
  23. Process process=new ProcessBuilder(command.split(" ")).
  24. start();
  25. System.out.println(process);
  26. PrintWriter out=new PrintWriter(
  27. new OutputStreamWriter(
  28. process.getOutputStream()));
  29. out.println("def");

  30. out.flush();
  31. }catch(IOException e){e.printStackTrace();}
  32. }
  33. public static void main(String[] args){
  34. Test.command("java Temp");
  35. }

  36. }</P>
复制代码

我想在Test中启动Temp,获得Temp重定向过的out,就是文件“hehe.txt”,然后在Test中继续往文件写入,为什么Temp没有执行?

您需要登录后才可以回帖 登录 | 加入黑马