欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

NIO 深入学习

程序员文章站 2022-07-04 08:45:12
...

package nio;

import java.nio.ByteBuffer;


public class TypesInByteBuffer {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

ByteBuffer buffer = ByteBuffer.allocate(64);

buffer.putInt(30);
buffer.putLong(99999999999L);
buffer.putDouble(Math.PI);

buffer.flip();

System.out.println(buffer.getInt());
System.out.println(buffer.getLong());
System.out.println(buffer.getDouble());
}

}



/**
*
*/
package nio;

import java.nio.FloatBuffer;

/**
* @author Administrator
*
*/
public class UseFloatBuffer {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

FloatBuffer buffer = FloatBuffer.allocate(10);

//放入数据
for(int i=0; i<buffer.capacity();++i){
float f = (float)Math.sin( (((float)i)/10)*(2*Math.PI) );
buffer.put(f);
}

//flip
buffer.flip();

while(buffer.hasRemaining()){
float f = buffer.get();
System.out.println(f);
}
}

}
相关标签: Java F#

上一篇: NIO学习

下一篇: NIO学习一、NIO简介