java中Buffer的概念是什么
时间:2024-04-02
浏览:492
作者:佚名
学习知识要善于思考,思考,再思考!今天golang学习网小编就给大家带来《java中Buffer的概念是什么》,以下内容主要包含等知识点,如果你正在学习或准备学习文章,就都不要错过本文啦~让我们一起来看看吧,能帮助到你就更好了!
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() + ",");
}
} 好了,本文到此结束,带大家了解了《java中Buffer的概念是什么》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多文章知识!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
12.01
12.01
12.01
热门专题
