I understand how to create a memory mapped file, but my question is let\'s say that in the following line:
FileChannel roChannel = new RandomAccessFile(file,
The size of the buffer is the size you pass in. It will not grow or shrink.
The javadoc says:
Maps a region of this channel's file directly into memory.
...
size - The size of the region to be mapped; must be non-negative and no greater than Integer.MAX_VALUE
EDIT:
Depending on what you mean by "updated with new data", the answer is yes.
The view of a file provided by an instance of this class is guaranteed to be consistent with other views of the same file provided by other instances in the same program. The view provided by an instance of this class may or may not, however, be consistent with the views seen by other concurrently-running programs due to caching performed by the underlying operating system and delays induced by network-filesystem protocols. This is true regardless of the language in which these other programs are written, and whether they are running on the same machine or on some other machine. The exact nature of any such inconsistencies are system-dependent and are therefore unspecified.
So, other systems may do caching, but when those caches are flushed or otherwise up-to-date, they will agree with the view presented by the FileChannel.
You can also use explicit calls to the position method and other methods to change what is presented by the view.
Changing the channel's position, whether explicitly or by reading or writing bytes, will change the file position of the originating object, and vice versa. Changing the file's length via the file channel will change the length seen via the originating object, and vice versa. Changing the file's content by writing bytes will change the content seen by the originating object, and vice versa.