如何在java中复制该程序的控制台输出

时间:2014-11-27 04:55:46

标签: java

package prgms;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

class new_experi
{

  public static void main(String[] args) throws IOException
 {
   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
   BufferedWriter out = new BufferedWriter(new FileWriter("C://Users//Abhilasha      U//Desktop//output.txt"));
  try 
    { 
      Process p=Runtime.getRuntime().exec("cmd /c dir"); 
      p.waitFor(); 
      BufferedReader reader=new BufferedReader(
          new InputStreamReader(p.getInputStream())
      ); 
      String line; 
      while((line = reader.readLine()) != null) 
      { 
          System.out.println(line);
      }  
    }
    catch(IOException e1) {} 
      System.out.println("Done");  
}
}

1 个答案:

答案 0 :(得分:0)

答案很简单。

package prgms;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

class new_experi
{

  public static void main(String[] args) throws IOException
 {
   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
   BufferedWriter out = new BufferedWriter(new FileWriter("C://Users//Abhilasha      U//Desktop//output.txt"));
  try 
    { 
      Process p=Runtime.getRuntime().exec("cmd /c dir"); 
      p.waitFor(); 
      BufferedReader reader=new BufferedReader(
          new InputStreamReader(p.getInputStream())
      ); 
      String line; 
      while((line = reader.readLine()) != null) 
      { 
          System.out.println(line);
      }  
    }
    catch(IOException e1) {} 
      System.out.println("Done");  
// This will pause your application so that you can take a screen shot !!
   System.in.read();
}
}

如果您在IDE上运行此程序,请编译此程序并运行它。一旦在控制台中看到它。按Alt + Print屏幕按钮,然后它将打印您的控制台屏幕。