`
sunxboy
  • 浏览: 2828305 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Java 读文件操作

 
阅读更多

1. only use java core, no external utils

String jsonContent = new Scanner(new File(getClass().getResource(jsonFilePath).getFile())).useDelimiter("\\Z").next()

 

2. use guava

URL url = Resources.getResource("foo.txt");
String text = Resources.toString(url, Charsets.UTF_8);

 

enjoy

分享到:
评论
1 楼 sunxboy 2014-07-09  
useful codes for java IO:
FileChannel channel = new RandomAccessFile(file, "r").getChannel();
ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
(from http://stackoverflow.com/questions/10364370/java-dynamic-sub-string-extraction-from-file-fast-way)

相关推荐

Global site tag (gtag.js) - Google Analytics