-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
DBD,
On 7/16/2011 10:46 AM, Dark Before Dawn wrote:
> Since I have no exposed filesystem getRealPath will return null. So
> I tried to use getResourceAsStream wich works fine for files but not
> for directories.
Are you sure you want to do this?
> My other idea was to use getResource and URL/URI to get a
> java.io.File via JNDI. But this file is not a file nor a directory.
How is this file not a file?
> // null if unpackWar = false String absolute =
> this.getServletConfig().getServletContext().getRealPath("files");
> out.write("Files: " + absolute);
>
> // jndi URL url =
> this.getServletConfig().getServletContext().getResource("files");
Read the javadoc for ServletContext.getResource:
"
Returns a URL to the resource that is mapped to a specified path. The
path must begin with a "/" and is interpreted as relative to the current
context root.
"
> InputStream is =
> this.getServletConfig().getServletContext().getResourceAsStream("files/1.txt");
This
>
should work, as long as you're using the API properly.
> // NPE if directory
That makes sense. You need to check for null, just like the javadocs say.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk4kSLsACgkQ9CaO5/Lv0PDn5wCfcXyA3/YahOeHpiiaKWTxgIcG
/9kAoJNThIueIkq+08FsWLUxT3dfZa6e
=6KeA
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]