• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading bytes from FileChannel...  RSS feed

 
Lionel Kingsley
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to read file content into bytebuffer and then decode ByteBuffer bb to CharBuffer. At last i want to close the FileChannel and delete the inputFile. I tried the following program.



The above program works fine. FileChannel.map() method directly maps to the file and get the MappedByteBuffer. But it has a drawback of not releasing the file even though the FileChannel gets closed. It has been reported as a bug in Sun java bug database.

I came to know that if i use FileChannel.read() method to resolve the problem i got. So i tried the following program.



I wonder it is not decoding the bytebuffer to charbuffer.

Please help me to resolve this problem.

Thank you.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do not really require a non blocking IO then instead of using channels you can use any implementations of java.io.Reader. These are convenience classes just for reading character streams.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!