FileChannel: close()
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class MainClass {
public static void main(String args[]) {
RandomAccessFile randomAccessFile;
FileChannel fileChannel;
ByteBuffer byteBuffer;
try {
randomAccessFile = new RandomAccessFile("test.txt", "rw");
fileChannel = randomAccessFile.getChannel();
byteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 26);
for (int i = 0; i < 10; i++)
byteBuffer.put((byte) ('A' + i));
fileChannel.close();
randomAccessFile.close();
} catch (IOException exc) {
System.out.println(exc);
System.exit(1);
}
}
}
Home
Java Book
File Stream
Java Book
File Stream
FileChannel:
- FileChannel
- FileChannel.MapMode.READ_WRITE
- FileChannel: close()
- FileChannel: lock(long position, long size, boolean shared)
- FileChannel: map(MapMode mode, long position, long size)
- FileChannel: position()
- FileChannel: position(long newPosition)
- FileChannel: read(ByteBuffer dst)
- FileChannel: size()
- FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
- FileChannel: transferTo(long position, long count, WritableByteChannel target)
- FileChannel: tryLock()
- FileChannel: write(MappedByteBuffer buffer)