struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Chacón Sánchez" <danielc...@gmail.com>
Subject Re: OutputStreamPath
Date Thu, 01 Mar 2007 21:07:14 GMT
Yes you are right, but what i have in the properties file is the database to
which the user wants to connect, for example oracle or sql.

Thanks

2007/3/1, Laurie Harper <laurie@holoweb.net>:
>
> Dave Newton wrote:
> > --- Daniel Chacón Sánchez <danielccss@gmail.com>
> >> I have a question, how I can set the path for the
> >> OutputStream like i get it for the InputStream with
> >> getResourceAsStream?
> >
> > I'm not sure you can do that, particularly since a
> > resource might be inside a JAR file or be located in a
> > place you do not have write acess to.
>
> Yup, there's no guarantee that the contents of a webapp can be written
> to in all deployment contexts. However, as long as you know you will be
> deploying it to a container that allows the file to be written to, you
> should be OK.
>
> > If you know that the properties file is in a specific
> > place and that it makes sense to write to it then I
> > would think you'd use typical file i/o and determine
> > the path via getRealPath.
>
> In your case, a simple change to the code you've already written should
> do the trick. Something like this (untested):
>
>      URL res = Thread.currentThread()
>          .getContextClassLoader()
>          .getResource(pathToConfigurationFile);
>
>      InputStream input = new FileInputStream(res);
>
>      //Load the properties
>      properties.load(input);
>      input.close();
>
>      ...
>
>      // Save the properties
>      OutputStream out = new FileOutputStream(res);
>      properties.store(out, "");
>
> > It confuses me why you'd want to do this in a webapp,
> > though. Settings you are likely to modify from within
> > the app should be in a database, not a properties file
> > (IMO, anyway).
>
> Agreed. Or otherwise externalized, for example through JNDI or something.
>
> L.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message