Hai friends, I have an application where i have given a lot of system.out.println statements. I want to save all these printing contents to be moved to a file. In C prog i have done this by giving the file pointer as 0 and whatever i prints on the screen moves to the file. Is there any facility available here with java.
Jithesh K
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi Jithesh Well can't you just redirect via system's redirection of output (if you are running your program from a prompt)? I mean like, bash$java program > output.txt OR you can use Streams' PrintWriter following way, PrintWriter out = new PrintWriter(new FileWriter(new File("output.txt"))); and then use 'out' for printing wherever you would put System.out.println() (you have to just use out.println() method here).... Regards Maulin
Thanks Moulin, I was really trying hard to do that. because i did that in c and not able to do it over in java. In this case what actually happens. whether the file pointer is set to zero or just resetting the out class.
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
Try System.setOut( your file output stream ) ? Might want to setErr too.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
vasu maj
Ranch Hand
Joined: Jul 12, 2001
Posts: 393
posted
0
Did you think about using aspects and point cuts? I have a feeling that you can use AOP in cases like this. Try posting this in Java Other products and servers thread. Author Ramnivas Laddad is presently answering questions.
Thanks, Vasu
What a wonderful world!
Jithesh Kozhipurath
Ranch Hand
Joined: Aug 27, 2003
Posts: 76
posted
0
Hai friends, Could u just explain in brief that what is the AOP.
My problem is just to move th contents to written on the screen to file. It should be done by just giving the system.out statement.
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
Aspect Oriented Programming is a pretty cool new thing. Crosscutting is a key word. You define some change to make to Java code in a file outside your normal Java source. You tell it how to identify the spot - maybe on entry to every method, or when a particular exception is thrown - and what to change - say log the method entry or exception. The AOP processor applies these changes to your source code and/or compiled byte code (not sure). The change "cuts across" any number of methods or classes. I'm not sure if I like the idea or not yet. AspectJ Guide AspectJ Home
Brian Pipa
Ranch Hand
Joined: Sep 29, 2003
Posts: 299
posted
0
Most of the logging APIs out there support redirection of System.out to a log file. I know log4J does for sure. You wouldn't have to change all of your printlns if you went with that solution. brian