struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: OutputStreamPath
Date Sat, 03 Mar 2007 00:15:33 GMT
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Dave,
> 
> Dave Newton wrote:
>> --- Laurie Harper <laurie@holoweb.net> wrote:
>>>      URL res = Thread.currentThread()
>>>          .getContextClassLoader()
>>>          .getResource(pathToConfigurationFile);
>>>      // Save the properties
>>>      OutputStream out = new FileOutputStream(res);
>>>      properties.store(out, "");
>> Ooo, I didn't know that.
>>
>> Hopefully I'll never want to use it, but still really
>> good to know! :)
> 
> I'm not sure where this will work. FileOutputStream doesn't accept a URL
> as a constructor argument. I think it's something more involved like:
> 
> URL res = ...;
> URLConnection conn = res.openConnection();
> conn.setDoOutput(true);
> OutputStream out = conn.getOutputStream();
> 
> ....
> 
> Of course, you'd want lots of error checking, too.
> 
> It's still butt-ugly.

Or, more simply,

URL res = ...;
String path = res.getPath();
OutputStrem out = new FileOutputStream(path);
...

I think you should be guaranteed a file URL from getResource(), at least 
in the situations where this whole approach is viable (i.e. where the 
target file is going to be a writable resource).

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message