逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::
From: http://bbs.csdn.net/topics/390577067
/**

     * 内存映射
     * 
     * 
@throws IOException
     
*/
    
public static void mapChannel() throws IOException {
        
long t1 = System.currentTimeMillis();
        FileInputStream in 
= new FileInputStream("d:/1.txt");
        
long size = in.available();
        RandomAccessFile out 
= new RandomAccessFile("d:/2.txt""rw");
        FileChannel inc 
= in.getChannel();
        MappedByteBuffer bf 
= inc.map(FileChannel.MapMode.READ_ONLY, 0, size);
        FileChannel outc 
= out.getChannel();
        MappedByteBuffer outbf 
= outc.map(FileChannel.MapMode.READ_WRITE, 0, size);
        outbf.put(bf);
        inc.close();
        outc.close();
        in.close();
        out.close();
        
long t2 = System.currentTimeMillis();
        System.out.println(t2 
- t1);
    }
posted on 2013-09-03 11:23 逛奔的蜗牛 阅读(695) 评论(0)  编辑 收藏 引用 所属分类: Java

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理