本帖最后由 真实姓名被注册 于 2015-7-20 14:36 编辑
- <P>import java.util.*;
- import java.io.*;
- public class Temp{
- public static void main(String[] args){
- System.out.println("执行Temp");
- File file=new File("hehe.txt");
- try {
- System.setOut(new PrintStream(
- new BufferedOutputStream(
- new FileOutputStream("hehe.txt"))));
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("abc");
- System.out.flush();
- }
- }
- import java.io.*;
- public class Test{
- public static void command(String command){
- try{
- Process process=new ProcessBuilder(command.split(" ")).
- start();
- System.out.println(process);
- PrintWriter out=new PrintWriter(
- new OutputStreamWriter(
- process.getOutputStream()));
- out.println("def");
- out.flush();
- }catch(IOException e){e.printStackTrace();}
- }
- public static void main(String[] args){
- Test.command("java Temp");
- }
- }</P>
复制代码
我想在Test中启动Temp,获得Temp重定向过的out,就是文件“hehe.txt”,然后在Test中继续往文件写入,为什么Temp没有执行?
|
|