Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Console output !!!???

843810Feb 23 2006 — edited Mar 22 2006
Hi,
i have redirectioned the java outoup to write in a file, it reacts perfectly to the system.out but when the new outpot becomes anything else as a printf nothing happens.

Anyone knows if it could be that the console is not "flusing" the messages.

all what i have tryed does not work and i am really desperado. So please it would be great any idea to solve the problem.

Here is what i have tryed, everything works with the system.out but not with the printf (maybe because the cmd is blocked??????) :
1.-
<code>
public static void main(String argh_my_aching_fingers[]){
//-----------------------------------------------------
final JTextArea textArea = new JTextArea(15, 40);
// Get the default system.out

final PrintStream sysOut = new PrintStream(System.out);

System.setOut(new PrintStream(new OutputStream() {
public void write(int b) throws IOException {
// write to the text area
textArea.append(String.valueOf((char)b));
// write to the default System.out
sysOut.write(b);
}
}));
}


2.-
public static void main(String argh_my_aching_fingers[]){
try
{
// create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

// read a line from the console
String lineFromInput = in.readLine();

// create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("myoutput.txt"));

// output to the file a line
out.println(lineFromInput);

// close the file (VERY IMPORTANT!)
out.close();
}
catch(IOException e)
{
System.out.println("Error during reading/writing");
}

}

the file only received the messages from the system.out


3.- the same, at least to write into a file everything but again failed.
<code>
// escribir en un archivo no funciona
try {
// Tee standard output
PrintStream out = new PrintStream(new FileOutputStream("out.log"));
PrintStream tee = new TeeStream(System.out, out);

System.setOut(tee);

// Tee standard error
PrintStream err = new PrintStream(new FileOutputStream("err.log"));
tee = new TeeStream(System.err, err);

System.setErr(tee);
} catch (FileNotFoundException e) {
}

// Write to standard output and error and the log files
System.out.println("welcome");

MainLogical logicalJava = new MainLogical();
logicalJava.GetIECRI1();// .GetInformationCommands();
System.out.println("bye");
<endcode>

NOTE / HINT:
that is the interface of the console:

<code>
//Make sure a nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
JFrame frame = new JFrame("Ls test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(textArea,BorderLayout.CENTER);
frame.setSize(100,100);//setExtendedState(MAXIMIZED_BOTH);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
//-----------------------------------------------------

<endcode>

It would be super if anyone who face with this, could help me
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2006
Added on Feb 23 2006
8 comments
428 views