使用ByteBuffer存储字符串
import java.nio.ByteBuffer; import java.nio.CharBuffer; public class Main {//来自 n o w j a v a . c o m public static void main(String[] args) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); CharBuffer cbuf = buf.asCharBuffer(); cbuf.put("a string"); cbuf.flip(); String s = cbuf.toString(); // a string /*时 代 J a v a - N o w J a v a . c o m 提供*/ // Get a substring int start = 2; // start is relative to cbuf's current position int end = 5; CharSequence sub = cbuf.subSequence(start, end); // str } }