集册 Java实例教程 创建阅读

创建阅读

欢马劈雪     最近更新时间:2020-01-02 10:19:05

473
创建一个只读的内存映射文件

import java.io.File;

import java.io.IOException;
/**来自 
 NowJava.com - 时代Java**/

import java.io.RandomAccessFile;

import java.nio.ByteBuffer;

import java.nio.channels.FileChannel;


public class Main {


  public void main(String[] argv) {

    try {

      File file = new File("filename");


      // Create a read-only memory-mapped file

      FileChannel roChannel = new RandomAccessFile(file, "r").getChannel();

      ByteBuffer roBuf = roChannel.map(FileChannel.MapMode.READ_ONLY, 0,

          (
展开阅读全文