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.
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.
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.
What a wonderful world!
Joined: Aug 27, 2003
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.
Joined: Jan 29, 2003
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