• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Reading / writing to a file  RSS feed

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Brossard
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!