How to get FileChannel from resource

Alan Bateman Alan.Bateman at Sun.COM
Mon Mar 2 13:18:31 UTC 2009

Ulf Zibis wrote:
> Sherman, yes, you are right. That's not what I'm looking for.
> This would be slower, than reading the stream directly, because the 
> underlying byte array will be copied 2 times by 
> BufferedInputStream#<init> + Channels.ReadableByteChannelImpl#read(),
> ... but maybe not, because looping BufferedInputStream#readChar() 
> could be slower than twice System.arraycopy().
> 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 ?
A URL just identifies an abstract resource so it may not support random 
access or other file-like operations you require. Have you thought about 
special handling for when the scheme is "file"? That way you can get the 
FileChannel you want for the typical case.


More information about the core-libs-dev mailing list