Read from standard output in java?
|
Original Message
|
Name: G Chen
Date: July 14, 2004 at 17:53:13 Pacific
Subject: Read from standard output in java?OS: win2kCPU/Ram: 1.8g/256m |
Comment: Folks: For example, HelloWorld.java prints out "Hello World" to standard output (screen display) . How can I write another java program to capture the output "Hello World" after HelloWorld.java is executed? I just don't want to use a temp file to store the data. Can somebody provide me couple lines of code as a hint? Thanks a lot !!! gangchen
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Tugg
Date: July 15, 2004 at 05:56:35 Pacific
|
Reply: (edit)Not quite sure what you mean with capture but im gonne assume you want to print Hello World to a file instead of the Screen... This would look like the following: import java.io.*; class HelloWorldOutput { public static void main(String args[]) { //declare output stream FileOutputStream out; //Declare PrintStream PrintStream p; try { //open OutputStream out = new FileOutputStream("myfile.txt"); //Link PrintStream to out p = new PrintStream(out); //capture text p.println("Hello World"); //Close Stream p.close(); } catch(Exception e) { System.err.println("File Output Error"); } } } This code should write Hello World into a text file in the same folder where your .class file is located. If you have any questions bout the code above let me know :)
Hope it helped ~TuGG~
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: