RandomAccessFile.setLength(1024*1024); // 预分配 1M 的文件空间  
RandomAccessFile 插入写示例:
/**
 * 
 * @param skip 跳过多少过字节进行插入数据
 * @param str 要插入的字符串
 * @param fileName 文件路径
 */
public static void beiju(long skip, String str, String fileName){
try {
RandomAccessFile raf = new RandomAccessFile(fileName,"rw");
if(skip <  0 || skip > raf.length()){
System.out.println("跳过字节数无效");
return;
}
byte[] b = str.getBytes();
raf.setLength(raf.length() + b.length);
for(long i = raf.length() - 1; i > b.length + skip - 1; i--){
raf.seek(i - b.length);
byte temp = raf.readByte();
raf.seek(i);
raf.writeByte(temp);
}
raf.seek(skip);
raf.write(b);
raf.close();
} catch (Exception e) {
e.printStackTrace();
}
}