I just see your answer, thanks!!! In fact is the same that the solution i
Found, Thanls!!!!

2007/3/1, Laurie Harper <[EMAIL PROTECTED]>:

Dave Newton wrote:
> --- Daniel Chacón Sánchez <[EMAIL PROTECTED]>
>> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to