File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes change standard output to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "change standard output to a file" Watch "change standard output to a file" New topic
Author

change standard output to a file

Yan Bai
Ranch Hand

Joined: Jul 21, 2002
Posts: 125
I remember there's a way for System.out output to a file, so it can be saved easily. does anyone know how?

THanks.


SCJP 1.4
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
When you start Java from the command line you can redirect the output:

Once your code is running you can change where stdout goes

Does one of those do what you need?


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
Yan Bai
Ranch Hand

Joined: Jul 21, 2002
Posts: 125
Thanks Stan.
1st one cannot be used coz it's a web application.
I am curious about the 2nd option. how can it be used in a web environment?
or is there a way to change the default output device from screen to something else?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What exactly do you need to do???


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Yan Bai
Ranch Hand

Joined: Jul 21, 2002
Posts: 125
I have 'System.out' lines in jsp/servlet pages, for basic debug purpose. Since the default system.out and system.err devices are the screen, the output information I specified are all mixed with Tomcat's embedded msg.

I want to seperate the information, e.g. let Tomcat intact, but output my system.out to somewhere else, such as a plain text file.

Instead of writing a redirect program by my own, I remember there's a way to change teh default output device for JVM, but how? your inputs are very appreicated...
Yan Bai
Ranch Hand

Joined: Jul 21, 2002
Posts: 125
Thanks Stan,
the 2nd option works great.
Ramen Chatterjee
Ranch Hand

Joined: Apr 27, 2006
Posts: 62
Hi

Just to clariy..

.. 1>stdout.txt 2>err.txt

First part means redirect std out to file
Second part means redirect std error to file

BTW, if these are servlets why not use the log() method?

Regards

Ramen


Could try harder
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
yes servlet-containers (like tomcat) use themselves logging frameworks. so go use them, too.

you really should avoid use System.out. for logging messages, soon or after it gets a pain: it's difficult to redirect it, no enforement of an output pattern, no simple switching off etc.

try out log4j


aldana software engineering blog & .more
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: change standard output to a file
 
Similar Threads
Cannot Open Excel file in Browser. + JSF + JSP + Bean
the Race
How to export Non-English Data from jsp file to excel file
how to make visible 2 combo boxes
Exception initiating Driver in Cron Job