Write byte array to a file with FileChannel from RandomAccessFile in Java
Description
The following code shows how to write byte array to a file with FileChannel from RandomAccessFile.
Example
//from w ww .j ava2 s.co m
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class Main {
private static final int BSIZE = 1024;
public static void main(String[] args) throws Exception {
FileChannel fc = new RandomAccessFile("data.txt", "rw").getChannel();
fc.position(fc.size());
fc.write(ByteBuffer.wrap("Some more".getBytes()));
fc.close();
}
}