Printing to a file from a jsp on a server.

I want to print stats to a file from a jsp, on the machine that the jsp is running on i.e.

the name of the machine is "test"  the jsp is running on a server on this machine
and i want to create a file on that server under a specific directory i.e


where test is a root directory.

I also want to be able to append data to this file without it being over written, how
is it possible to do that.

Any help greatly appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

<% bw = null ;
        bw = new BufferedWriter( new FileWriter( "/test/logs/log.txt", true ) ) ;
        bw.write( "Hi there at " + new Date().toString() + "\n" ) ;
    catch( ex )
        ex.printStackTrace() ;
        try { if( bw != null ) bw.close() ; } catch( ex ) {}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Also, look at the apache.commons.logging libraries (which I think come with tomcat)
pronaneAuthor Commented:
cheers tim

does the write method append to a file OR WRITE over previous content?

Also what if any given folder on that server isnt world writeable, will the jsp
still be able to create a file under that folder?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

> new FileWriter( "/test/logs/log.txt", true )

The "true" parameter means it will append to the file :-)
> Also what if any given folder on that server isnt world writeable, will the jsp
> still be able to create a file under that folder?

It depends on the access rights of the tomcat process...

If the user that is considered to be running tomcat has no write access to that folder, it will get an IOException, and not create/append that file...
*sniff* only a B grade :-(

Good luck with it...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.