创建一个带有孔的文件
import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer;/* 来自 n o w j a v a . c o m*/ import java.nio.channels.FileChannel; public class Main { public static void main(String[] argv) throws IOException { File temp = File.createTempFile("holy", null); RandomAccessFile file = new RandomAccessFile(temp, "rw"); FileChannel channel = file.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(100); /** 来 自 N o w J a v a . c o m - 时 代 Java **/ putData(0, byteBuffer, channel); putData(5000000, byteBuffer, channel); putData(50000, byteBuffer, channel); // Size will report the largest position written System.out.println("Wrote temp file '" + temp.getPath() + "', size=" + channel.size()); channel.close(); file.close(); } private static void putData(int position, ByteBuffer buffer, FileChannel channel)