String lineseperator = java.security.AccessController .doPrivileged(new sun.security.action.GetPropertyAction( "line.separator"));

Access restriction: The constructor 'GetPropertyAction(String)' is not API

Access restriction on class due to restriction on required library rt.jar?

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode; public class memorymapfiledemo {
final static String filepath = "/home/hadoop/test/java.txt"; public static void main(String[] args) throws IOException {
writefile(filepath);
readfile(filepath);
} static void writefile(String _filepath) throws IOException {
File _file = new File(_filepath);
RandomAccessFile raf = new RandomAccessFile(_file, "rw");
FileChannel fc = raf.getChannel();
int buffersize = 1024 * 8;
CharBuffer cb = fc.map(MapMode.READ_WRITE, 0, buffersize)
.asCharBuffer();
String lineseperator = java.security.AccessController
.doPrivileged(new sun.security.action.GetPropertyAction(
"line.separator"));
String content = "";
long offset = 0;
for (int i = 1; i <= 1000; i++) {
content = "Line" + i + " hello java" + lineseperator;
if ((cb.limit() - cb.position()) < content.length()) {
offset += cb.position();
cb = fc.map(MapMode.READ_WRITE, offset, buffersize)
.asCharBuffer();
}
cb.put(content);
}
fc.close();
raf.close();
} static void readfile(String _filepath) throws IOException {
File _file = new File(_filepath);
RandomAccessFile raf = new RandomAccessFile(_file, "rw");
FileChannel fc = raf.getChannel();
long totalsize = fc.size();
int buffersize = 1024 * 8;
long offset = 0;
CharBuffer cb = fc.map(MapMode.READ_ONLY, 0, buffersize).asCharBuffer();
while (offset < totalsize) {
while (cb.hasRemaining()) {
System.out.print(cb.get());
}
offset += cb.position();
cb = fc.map(MapMode.READ_ONLY, offset, buffersize).asCharBuffer();
}
fc.close();
raf.close();
}
}

java Memorymapfile demo的更多相关文章

  1. 微信公众号Java接入demo

    微信公众号Java接入demo 前不久买了一台服务,本来是用来当梯子用的,后来买了一个域名搭了一个博客网站,后来不怎么在上面写博客一直闲着,最近申请了一个微信公众号就想着弄点什么玩玩.周末没事就鼓捣了 ...

  2. Kafka2.4发布——新特性介绍(附Java Api Demo代码)

    新功能 允许消费者从最近的副本进行获取 为 Consumer Rebalance Protocol 增加对增量协同重新均衡(incremental cooperative rebalancing)的支 ...

  3. appium+java+junit demo运行

    对java熟悉一些,所以想用java把appium给做起来.今天用myeclipse给环境和Demo弄了一下,网上没有一篇全套资料的. 各块环境的搭建: 1.安装appium客户端,省略下载和安装步骤 ...

  4. 微博开发平台java SDK demo学习之friendships

    本文解释了在java SDK的demo中与feiendships有关的功能 截图如下: 关注一个用户(需要知道该用户uid) 取消关注一个用户(用户uid) 获取用户粉丝列表(授权用户的screen_ ...

  5. 快递鸟物流单号自动识别接口JAVA对接demo

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  6. java迭代器demo

    package cn.aust.zyw.demo; import java.util.Iterator; /** * Created by zyw on 2016/2/16. * Iterator模式 ...

  7. Java Design Demo -简单的队列-异步多任务队列(java android)

    简单的单线程队列 -- 工作的时候遇到劣质打印机.给打印机发消息,打印机就会打印,如果在打印机还在打印的时候,就 再发消息打印,就会出现消息丢失.所以需要给上一个任务一些处理的间隔时间. 单线程的消息 ...

  8. Floyd算法java实现demo

    Floyd算法java实现,如下: https://www.cnblogs.com/Halburt/p/10756572.html package a; /** * ┏┓ ┏┓+ + * ┏┛┻━━━ ...

  9. solr环境搭建及java小demo

    一配置solr环境 1.下载solr 2.配置solr(最好单独分离出一个tomcat,一台机器启动多个tomcat参见:http://www.cnblogs.com/lxlwellaccessful ...

随机推荐

  1. [CLR via C#]14. 字符、字符串和文本处理

    一.字符 在.NET Framewole中,字符总是表示成16位Unicode代码值,这简化了国际化应用程序的开发. 每个字符都表示成System.Char结构(一个值类型) 的一个实例.System ...

  2. Win764位配置Github环境及将代码部署到Github pages-志银强势总结

    (软件及教程下载分享:链接:http://pan.baidu.com/s/1dFysay9 密码:pug0) 1-安装Git-2.9.2-64-bit.exe(解压安装文件,运行安装程序,除了记得修改 ...

  3. linux服务开机启动顺序

    今天遇到了一个问题,我们写了一个服务脚本A,该服务需要优先于mysql启动.脚本是从其他地方拷来的模板,前面的默认配置没改,只是实现了自己的功能.写完,chkconfig A on,reboot,启动 ...

  4. 初识 easyui datagrid

    首先应该下载好easyui datagrid所用的各种js 和css 这个可以到官网上去下载. 首先要引入datagrid所引入的js和css. <script src="js/jqu ...

  5. 六个创建模式之单例模式(Singleton Pattern)

    定义: 确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.三个特点:一个类只有一个实例:必需自己创建这个实例:必需自行向整个系统提供这个实例. 结构图: Singleton:单例类,提 ...

  6. js得到屏幕宽高、页面宽高 (window.screen.availHeight)等--笔记

    window.screen.availWidth 返回当前屏幕宽度(空白空间) window.screen.availHeight 返回当前屏幕高度(空白空间) window.screen.width ...

  7. 对CSS进行wxss思路学习,display属性。

    先来概要一下学习思路: 本系列内容,将针对微信小程序中的WXSS学习,所以在学习CSS时每一个知识点都在小程序IDE中进行实践,达到最好的学习效果. 由于wxss与CSS有些许不同,在学习CSS过程中 ...

  8. SharePoint 2013 中的SQL Server 安全

    使用SharePoint很长时间以来,都认为Sql只需要最初始的配置,即不再需要管理和维护:而事实上,Sql的管理和安全,都是和SharePoint环境的稳定性息息相关的,所以,要绝对重视ShareP ...

  9. [Microsoft Dynamics CRM 2016]Invalid Action – The selected action was not valid 错误的诱因及解决方法

    详细问题描述: 由于解决windows server 评估版过期\SQL server 评估版过期的问题后而导致的Invalid Action – The selected action was no ...

  10. iOS--APP 登录界面图(xuer)

    ViewController.h #import "ViewController.h" @interface ViewController () @property(strong, ...