failed to use RandomAccessFile.setLength() to truncate the file

M

mytkdd

hi, everyone,

i used to use RandomAccessFile.setLength() to truncate the file from a
given postion, for example, from "abcdeabcde" to "abcde" .

but if i map a region of this file into memory using
RandomAccessFile.getFileChannel() and FileChannel.map() while i am
dealing with large file for example 2GB, the api can not work. The
runtime error shows this method can not work while using memory
mapping, even i close and open a new RandomAccessFile object or clear
the MappedByteBuffer object.

Now i don't know how to truncate the file while using memory
mapping.Does anyone konw how?

thanks in advance.

tkdd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top