java中Buffer的概念是什么
作者:WeekendFlower
时间:2023-04-30
浏览:1
1、概念使用JavaNIOBuffers与NIOChannel交互。从Channel中读取数据到buffers里,从Buffer把数据写入到Channels;必须对Buffer的三个属性进行控制,即capacities能力、position-location、limit限制。2、实例publicstaticvoidmain(String[]args){//生成一个长度为10的缓冲区IntBufferintBuffer=IntBuffer.allocate(10);for(inti=0;i
本文目录
1、概念
使用Java NIO Buffers与NIO Channel交互。从Channel中读取数据到buffers里,从Buffer把数据写入到Channels;必须对Buffer的三个属性进行控制,即capacities能力、position-location、limit限制。
2、实例
public static void main(String[] args) {
//生成一个长度为10的缓冲区
IntBuffer intBuffer = IntBuffer.allocate(10);
for (int i = 0; i < intBuffer.capacity(); ++i){
int randomNum = new SecureRandom().nextInt(20);
intBuffer.put(randomNum);
}
//状态翻转
intBuffer.flip();
while (intBuffer.hasRemaining()){
//读取数据
System.out.print(intBuffer.get() + ",");
}
//clear方法本质上并不是删除数据
intBuffer.clear();
System.out.print("\n");
System.out.println("-----------------------------");
while (intBuffer.hasRemaining()){
System.out.print(intBuffer.get() + ",");
}
}
作者最新文章
Yandex引擎入口2026最新登录方式
2026-11-15 16:52
Yandex俄罗斯官网入口及最新搜索地址
2026-11-15 14:51
妖精漫画官网登录入口及首页指南
2026-11-13 11:26
再漫画官网首页入口及在线观看方法
2026-11-05 09:42
ArchiveofOurOwn官网链接及同人文学阅读入口
2026-10-30 10:21
上一篇:
Java线程优先级实例分析
下一篇:
Java中可用的位运算技巧有哪些?
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































