惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
D
Docker
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Cloudflare Blog
雷峰网
雷峰网
A
About on SuperTechFans
小众软件
小众软件
博客园 - Franky
博客园 - 聂微东
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
量子位
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
罗磊的独立博客
Martin Fowler
Martin Fowler
D
DataBreaches.Net
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
Project Zero
Project Zero
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
Security Latest
Security Latest
NISL@THU
NISL@THU
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks

博客园 - micenter

Register ASP.NET 4.0 An error has occurred: 0x8007b799 You must have administrative rights on this machine in order to ru 记录一些常用的SQLServer时间日期函数详解 IT民工的2013生活创想 SQL 日志太大,脚本清除 跟随博客园进入2012 .NET 中 操作excel 系列--copy功能. .NET 中 操作excel 系列--导入与导出. 设置VSS2005使支持通过Internet访问 中the server configuration settings apply only for local databases....问题解决 vss 2005 配置服务器端的时候提示"IIS没有安装" ASP.NET MVC 实现二级域名 [转] Eclipse快捷键大全(转载) Android单元测试测试[转] 手动使用EDM 生成器 (EdmGen.exe) 工具生成 SSDL,CSDL,MSL 文件。 InnoDB ,MyISAM 等存储引擎中主外键的大小设置. 在 mysql 中 定义 数据库,表,列时,设定的各个的编码格式。 asm.jar 等包的重用问题之解决方案 汇总 Hibernate 与 jdbc,jndi+dbcp, proxool ,c3p0 连接池的配置 - micenter Hibernate中自动增长列的 在Annotations 中的配置和数据库设置默认值问题 - micenter Hibernate中自动增长列的..hbm.xml 配置和数据库设置默认值问题 - micenter - 博客园
java 字符串的编码与C#的区别 - micenter - 博客园
micenter · 2009-12-23 · via 博客园 - micenter

   1, 字符串 转换为字节数组 时的区别。

      JAVA: 当我们使用方法 getBytes() 转换为byte数组时 如:

使用UTF-8 时:

String str="我是中国人";

byte[] result=str.getBytes("utf-8");

输出结果为:[-26, -120, -111, -26, -104, -81, -28, -72, -83, -27, -101, -67, -28, -70, -70]

      C# : 使用System.Text.Encoding.UTF8.GetBytes(str);

输出结果为:[230, 136, 145, 230, 152, 175, 228, 184, 173, 229, 155, 189, 228, 186, 186]

使用GB2312时 :

java输出: [-50, -46, -54, -57, -42, -48, -71, -6, -56, -53]
C#输出:  [206, 210, 202, 199, 214, 208, 185, 250, 200, 203]

 我们发现 java 中输出的是都是 C#输出-256 的值  如上两中第一个 : 206-256=-50 ,  偶较愚钝不知为什么会这样,如果有哪位N人经过看到了,还望指点,指点。

   2, 上面的虽然byte数组内的值不一样,但最各自转换成 Base64 的String 类型的值是一样的,而当我们用上UTF-16时却有点要当心的地方,我们都知道在C#里面有System.Text.Encoding.Unicode.GetBytes(str) 方法,其中的Unicode 编码就是UTF-16 格式的,然而当我们在java 里也用String.getBytes(“utf-16”) 格式码时得到的结果解码出来却是不一样的不是等于 C#输出-256 的值  会多出两个值 且自转换成 Base64 的String 类型的值是不一样的,但当我们把java 里的UTF-16 变成 UTF-16LE 时,发现转换成 Base64 的String 类型的值是一样的, 由些可以看出 在C#中的 Unicode 编码对应 JAVA  中的是 UTF-16LE 格式 而不是 UTF-16 。