这里面包含了一百多个JAVA源文件

源代码在线查看: e162. getting and setting non-byte java types in a bytebuffer.txt

软件大小: 551 K
上传用户: maple_78
关键词: JAVA
下载地址: 免注册下载 普通下载 VIP

相关代码

				The ByteBuffer class provides convenience methods for getting and putting other multibyte Java primitive types. There are two issues to be aware of when using these methods. First, ensure that values will be stored using the desired byte ordering; see e165 Setting the Byte Ordering for a ByteBuffer for more information. Second, the hasRemaining() method cannot be used to determine if the buffer has room for a multibyte put. If your application needs to know this information, see e163 Creating a Non-Byte Java Type Buffer on a ByteBuffer for an example that can provide this information. 
				    // Obtain a ByteBuffer; see also e158 Creating a ByteBuffer
				    ByteBuffer buf = ByteBuffer.allocate(100);
				    
				    // Put values of different types
				    buf.putChar((char)123);
				    buf.putShort((short)123);
				    buf.putInt(123);
				    buf.putLong(123L);
				    buf.putFloat(12.3F);
				    buf.putDouble(12.3D);
				    
				    // Reset position for reading
				    buf.flip();
				    
				    // Retrieve the values
				    char c = buf.getChar();
				    short s = buf.getShort();
				    int i = buf.getInt();
				    long l = buf.getLong();
				    float f = buf.getFloat();
				    double d = buf.getDouble();
				
							

相关资源