Пример #1
0
  @Test
  public void test1() throws Exception {
    java.lang.String s1 = "你们好吗";
    byte[] bytes = s1.getBytes("utf-8");
    System.out.println("字节长度:" + bytes.length);

    ByteArrayInputStream bi = new ByteArrayInputStream(bytes);

    // hhw:tag 下面的方式读取流的内容是有问题的
    byte[] buffer = new byte[10];
    int len;
    StringBuffer sb = new StringBuffer();
    while ((len = bi.read(buffer)) != -1) sb.append(new String(buffer, 0, len, "utf-8"));

    System.out.println("得到的支付串:" + sb.toString()); // 得到的字符串是:你们好???
  }
Пример #2
0
 public void writeString(java.lang.String s) {
   s.getBytes(0, s.length(), buffer, currentOffset);
   currentOffset += s.length();
   buffer[currentOffset++] = 10;
 }