printing output to console & to a text file at the same time...
Hello everyone,
I want to send output at console and in a text file at same time in java.
Can anyone please help me out?
Thanks,
Prasanna
Re: printing output to console & to a text file at the same time...
I don't know if you can. What you can do is print out first to the screen and then print that to the file (or reverse order, it doesn't matter).
Re: printing output to console & to a text file at the same time...
How about Apache log4j 1.2 - log4j 1.2
This might be somewhat over course though.
// Json
Re: printing output to console & to a text file at the same time...
Quote:
Originally Posted by
helloworld922
I don't know if you can. What you can do is print out first to the screen and then print that to the file (or reverse order, it doesn't matter).
Yeah it's easy to do one at a time. Although this code prints to the console first, the file is written a fraction of a second later:
Code :
import java.io.*;
public class Prasanna {
/**
* JavaProgrammingForums.com
*/
public static void main(String[] args) throws IOException {
// Print to console
System.out.println("JavaProgrammingForums.com");
// Print to file
Writer output = null;
File file = new File("myFile.txt");
output = new BufferedWriter(new FileWriter(file));
output.write("JavaProgrammingForums.com");
output.close();
System.out.println("File written");
}
}