import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder; public class CharsetTransform {
public static void main(String[] args) throws CharacterCodingException {
Charset cn = Charset.forName("GBK");
CharsetEncoder cnEncoder = cn.newEncoder();
CharsetDecoder cnDecoder = cn.newDecoder(); CharBuffer cbuff = CharBuffer.allocate();
cbuff.put("良红");
cbuff.flip();
ByteBuffer bbuff = cnEncoder.encode(cbuff);
for (var i =; i < bbuff.capacity(); i++){
System.out.println(bbuff.get(i) + " ");
}
System.out.println("\n" + cnDecoder.decode(bbuff)); }
}

output:

-63
-68
-70
-20 良红

  

learning java Encoder and Decoder的更多相关文章

  1. 从Encoder到Decoder实现Seq2Seq模型

    https://zhuanlan.zhihu.com/p/27608348 更新:感谢@Gang He指出的代码错误.get_batches函数中第15行与第19行,代码已经重新修改,GitHub已更 ...

  2. Learning Java language Fundamentals

    Chapter 2 Learning Java language fundamentals exercises: 1.What  is Unicode? Unicode is a computing ...

  3. C# 字符编码解码 Encoder 和Decoder

    在网络传输和文件操作中,如果数据量很大,需要将其划分为较小的快,此时可能出现一个数据块的末尾是一个不匹配的高代理项,而与其匹配的低代理项在下一个数据块. 这时候使用Encoding的GetBytes方 ...

  4. TF之AE:AE实现TF自带数据集AE的encoder之后decoder之前的非监督学习分类—Jason niu

    import tensorflow as tf import numpy as np import matplotlib.pyplot as plt #Import MNIST data from t ...

  5. TF之AE:AE实现TF自带数据集数字真实值对比AE先encoder后decoder预测数字的精确对比—Jason niu

    import tensorflow as tf import numpy as np import matplotlib.pyplot as plt #Import MNIST data from t ...

  6. blogs for learning java

    曹海成的专栏 http://blog.csdn.net/caohaicheng/article/details/38071097 http://blog.csdn.net/a5489888/artic ...

  7. Learning Java IO indexes

    I/O Streams, it simplifies I/O operations, write a whole object out to stream & read back. File ...

  8. Learning Java 8 Syntax (Java in a Nutshell 6th)

    Java is using Unicode set Java is case sensitive Comments, C/C++ style abstract, const, final, int, ...

  9. Learning Java characteristics (Java in a Nutshell 6th)

    Java characteristics: Java .class files are machine-independent, including the endianness. Java .cla ...

随机推荐

  1. 深度学习-深度强化学习(DRL)-Policy Gradient与PPO笔记

    Policy Gradient 初始学习李宏毅讲的强化学习,听台湾的口音真是费了九牛二虎之力,后来看到有热心博客整理的很细致,于是转载来看,当作笔记留待复习用,原文链接在文末.看完笔记再去听一听李宏毅 ...

  2. Go基础编程实践(六)—— 文件

    检查文件是否存在 在此程序同目录下创建log.txt文件,以检测. package main import ( "os" "fmt" ) func main() ...

  3. 【LEETCODE】63、数组分类,hard级别,题目:85、4、84

    package y2019.Algorithm.array.hard; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.arr ...

  4. 引用和自包含令牌(Reference Tokens and Introspection)

    访问令牌可以有两种形式:自包含的和引用的. 自包含令牌(Self-contained tokens): 使用受保护的.有时间限制的数据结构,该结构包含元数据,并声明通过网络传递用户或客户机的身份.一种 ...

  5. Visual Studio 使用 Parallel Builds Monitor 插件迅速找出编译速度慢的瓶颈,优化编译速度

    原文:Visual Studio 使用 Parallel Builds Monitor 插件迅速找出编译速度慢的瓶颈,优化编译速度 嫌项目编译太慢?不一定是 Visual Studio 的问题,有可能 ...

  6. C#字符串连接问题(包含破折号和引号)

    1.需求场景: 生成字符串如下:jsonStr.Append("\"SensorTypes\":"); 解决方法: string code = @"j ...

  7. Thymeleaf前后端分页查询

    分页查询是一个很常见的功能,对于分页也有很多封装好的轮子供我们使用. 比如使用mybatis做后端分页可以用Pagehelper这个插件,如果使用SpringDataJPA更方便,直接就内置的分页查询 ...

  8. 05、MySQL—字符集

    1.字符编码概念 字符(Character)是各种文字和符号的总称,包括各国家文字.标点符号.图形符号.数字等. 在计算机中所看到的任何内容都是字符构成的. 字符编码(character code)是 ...

  9. Java 缓存实例

    重复创建相同的对象没有太大的意义,反而加大了系统开销,某些情况下,可以缓存该类的实例,实现复用. 实现缓存实例:定义一个private static成员变量存储类的实例(多个可用数组)先检测上面的成员 ...

  10. 为什么说pt-osc可能会引起主从延迟,有什么好办法解决或规避吗?

    若复制中binlog使用row格式,对大表使用pt-osc把数据从旧表拷贝到临时表,期间会产生大量的binlog,从而导致延时 pt-osc在搬数据过程中insert...select是有行锁的,会降 ...