RandomAccessFile: getChannel()
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
RandomAccessFile:
- RandomAccessFile
- new RandomAccessFile(String fileName, String mode)
- RandomAccessFile: close()
- RandomAccessFile: getChannel()
- RandomAccessFile: getFilePointer()
- RandomAccessFile: length()
- RandomAccessFile: read(byte[] b)
- RandomAccessFile: readBoolean()
- RandomAccessFile: readByte()
- RandomAccessFile: readChar()
- RandomAccessFile: readDouble()
- RandomAccessFile: readInt()
- RandomAccessFile: readLine()
- RandomAccessFile: seek(long pos)
- RandomAccessFile: write(byte[] b)
- RandomAccessFile: writeBoolean(boolean v)
- RandomAccessFile: writeBytes(String s)
- RandomAccessFile: writeChars(String s)
- RandomAccessFile: writeInt(int v)
- RandomAccessFile: writeUTF(String str)