"Craig R. McClanahan" wrote:
> Michael Caines wrote:
>
> > Is there a way for a servlet to alter and save a Properties object to a
> > file on the server? I want to allow the user to make changes to a
> > profile (a .properties file on the server), and have them persist on the
> > server without using a database.
> >
> > Here are the things I'm looking at:
> >
> > The java.util.Properties class has methods for loading and saving a
> > Properties object from a stream, but no setter method for changing
> > individual properties.
> >
>
> Umm, what's wrong with put(Object key, Object value)?
> It is inherited from Hashtable, which Properties is a subclass of.
>
This works, although it's strange to me why someone at Sun saw the need for
setProperty methods in the com.sun.server.util.ExProperties class...
[stuff deleted]
> >
> > There is the java.io.File class. This usually results in coding some
> > system-dependent filenames which I would like to avoid if possible. I
> > could also scrap the Properties approach and create my own flat-file for
> > storing profiles. However, I'd like to use a .properties file, since it
> > seems naturally suited for the task.
> >
>
> There's no problem using properties files, because you've got
> Properties.save() to write them out for you. I do this to a FileOutputStream
> all the time.
>
> The problem, of course, is that you have to know where to store them --
> probably configured via some initialization parameter to your servlet. But
> that applies to knowing where to read them from as well, if you are using the
> loadProperties() method.
>
I used ClassLoader::getResourceAsStream() to create an InputStream for the
Properties::load() method. This still leaves the problem of where to save the
Properties file. FileOutputStream works, but it looks like you have to provide
some system-dependent path/file info here (unless you specify it as an
initialization parameter somewhere, as you suggest, Craig). It would be slick if
you could somehow extract the path information from the original resource, and use
it to construct destination path info on the fly. However, I guess this would
defeat the purpose of having certain URL objects not support OutputStreams.
[more stuff deleted]
>
> >
> > Michael
> >
>
> Craig McClanahan
Michael
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html