• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Reading bytes from FileChannel...

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic