How to get FileChannel from resource

Tom Hawtin Thomas.Hawtin at Sun.COM
Mon Mar 2 13:13:36 UTC 2009


Ulf Zibis wrote:

> 
> Anyway, I'm looking for a DirectBuffer directly from a resource file.
> So I think there is something missing:
> URL.openChannel() or Class#getResourceAsChannel()
> 
> Maybe there is a way to get a RamdomAccessFile from URL to get the 
> Channel from. Anybody knows ?

If it's a file URL, then obviously you can check the protocol and create 
a `File` from the file portion. However most resources are not stored in 
naked files.

For jared resources, you can cast the URLConnection to JarURLConnection 
and call getJarFile. Some implementations of JarURLConnection may not 
return a JarFile.

Tom Hawtin



More information about the core-libs-dev mailing list