-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetData.java
More file actions
executable file
·61 lines (57 loc) · 1.52 KB
/
GetData.java
File metadata and controls
executable file
·61 lines (57 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package basic.nio;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
/**
* ��ȡ��������
*
* @author yangqc 2016.6.2
*/
public class GetData {
private static final int BSIZE = 1024;
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.allocate(BSIZE); //�����ֽ���
int i = 0;
while (i++ < bb.limit()) //�ж���ʼÿλ�Ƿ�Ϊ0
{
if (bb.get() != 0) {
System.out.println("nonzero");
}
}
System.out.println("i=" + i);
bb.rewind();
bb.asCharBuffer().put("Howdy!");
char c;
bb.rewind();
while ((c = bb.getChar()) != 0) {
System.out.print(c + " ");
}
// System.out.println(bb.position());
// bb.rewind();
CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
System.out.println(cb.remaining());
for (int j = 0; j < cb.remaining(); j++) {
cb.put(j, 'a');
System.out.println(bb);
}
while (cb.hasRemaining()) {
System.out.print((char) cb.get());
}
// System.out.println(bb.position());
System.out.println();
bb.rewind();
bb.asShortBuffer().put((short) -32769);
System.out.println(bb.getShort());
bb.rewind();
bb.asIntBuffer().put(89798798);
System.out.println(bb.getInt());
bb.rewind();
bb.asLongBuffer().put(9809L);
System.out.println(bb.getLong());
bb.rewind();
bb.asFloatBuffer().put(9879798f);
bb.rewind();
bb.asDoubleBuffer().put(2112);
System.out.println(bb.getDouble());
bb.rewind();
}
}