Java nio: How to read characters from memory mapped file with correct charset -
For a new project, I must read the letters of a file (with configurable encoding) to handle the input Since some of these files may be too large (> 100MB), I want to check for the fast access to Java map of the map of the map.
However, I could not understand how I used to do Madbethbuffer Right to create "Reader" with correct charset decoding I'm in
Mapbitbare, I currently use:
RandomAccessFile raFile = New RandomAccessFile ("myFile.bla", "r"); File channel channel = raFile.getChannel (); Maped buffer mapped batbuffer = channel.map (mappedod. Rad_only, 0, channel. Size ()); I know, I can use getChar () to get a character from the Mapbitbuffer, but how is it possible to specify the encoding? It is said in Javadok, that two bytes are always read and add one to four, but what happens with ASCII encoded files?
I got the channel too. Nerdar (...) methods, though handle only the channel, not the memory map file. Is anything similar to Mapbittberger?
Just to make sure: I know that memory mapping is some expensive operation and is therefore useful only for large files
Many thanks in advance + Best regards, Andreas
You can recover from your favorites.
StandardCharsets.UTF_8.newDecoder (). Decode (mapped buffer) This returns the returns you can make from.
Note that this uses the full mappedbitbuffer . If you want only a few bytes, create a new ByteBuffer with some bytes of the original MappedByteBuffer and decode it.
Comments
Post a Comment