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

Reading / writing to a file

David Brossard
Ranch Hand

Joined: Jun 03, 2004
Posts: 107
Hi,

I want to read data from a file and store data to it. If my app is effectively an axis web service, how can I access my file? With new File(String relativePath) ? Can I read a file in a jar? Write to a file in a jar?

What if I want to read/write to a file on the classpath rather than on the filesystem? Does this actually make any sense at all?

And in a class Apple in package com.foo.bar (hence com.foo.bar.Apple), what does the relative path relate to? The root of wherever folder com is? What if all of com has been jar-ed?

Thanks everyone!


No matter what they say in Ohio, we're still first in flight!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
Whether your class is a web service makes no difference to its I/O behavior. It's probably easiest to use paths that are relative to the context (which may be something like ".../axis"). Then you can construct absolute paths using the HttpServletRequest.getRealPath method. In Axis, you can obtain the HttpServletRequest as described here.


Ping & DNS - updated with new look and Ping home screen widget
David Brossard
Ranch Hand

Joined: Jun 03, 2004
Posts: 107
Yes, I've used that class in the past to create absolute paths. I wanted to ignore that because when I test out my components before deploying them as web services, they are simple apps.

Thanks for the tip anyway. Now I know there's no smart mechanism I should be using.
[ October 30, 2006: Message edited by: David Brossard ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading / writing to a file
 
Similar Threads
Using a jar inside my application
Include only specific directories when using jar command
Help reqd. jar file list and jar file name
Question on loading class from Jar File
Write and Read Object to File