java获取字节的长度.
来源:互联网 发布:mac连打印机 编辑:程序博客网 时间:2024/05/16 15:29
package pack.java.midea.dao;
import java.io.UnsupportedEncodingException;
/**
* 测试;
* @author zhouhaitao
* 2012-5-17
*/
public class Test {
/**
* @param args
* @throws UnsupportedEncodingException
*/
public static void main(String[] args) throws UnsupportedEncodingException {
// TODO Auto-generated method stub
Test test = new Test();
String a = "在";
test.getStringByteLength(a);
System.out.println("--------------------------------------");
String b = "A";
test.getStringByteLength(b);
String c = "1";
test.getStringByteLength(c);
}
/**
* 获取字符的所占字节长度;
* @param str
* @throws UnsupportedEncodingException
*/
private void getStringByteLength(String str) throws UnsupportedEncodingException{
System.out.println("\""+str+"\"字符所占的字节长度如下:");
System.out.println("ISO-8859-1:"+str.getBytes("ISO-8859-1").length);
System.out.println("UTF-8:"+str.getBytes("UTF-8").length);
System.out.println("GBK:"+str.getBytes("GBK").length);
System.out.println("GB2312:"+str.getBytes("GB2312").length);
System.out.println("GB18030:"+str.getBytes("GB18030").length);
System.out.println("UTF-16:"+str.getBytes("UTF-16").length);
}
import java.io.UnsupportedEncodingException;
/**
* 测试;
* @author zhouhaitao
* 2012-5-17
*/
public class Test {
/**
* @param args
* @throws UnsupportedEncodingException
*/
public static void main(String[] args) throws UnsupportedEncodingException {
// TODO Auto-generated method stub
Test test = new Test();
String a = "在";
test.getStringByteLength(a);
System.out.println("--------------------------------------");
String b = "A";
test.getStringByteLength(b);
String c = "1";
test.getStringByteLength(c);
}
/**
* 获取字符的所占字节长度;
* @param str
* @throws UnsupportedEncodingException
*/
private void getStringByteLength(String str) throws UnsupportedEncodingException{
System.out.println("\""+str+"\"字符所占的字节长度如下:");
System.out.println("ISO-8859-1:"+str.getBytes("ISO-8859-1").length);
System.out.println("UTF-8:"+str.getBytes("UTF-8").length);
System.out.println("GBK:"+str.getBytes("GBK").length);
System.out.println("GB2312:"+str.getBytes("GB2312").length);
System.out.println("GB18030:"+str.getBytes("GB18030").length);
System.out.println("UTF-16:"+str.getBytes("UTF-16").length);
}
}
控制台输出结果:
--------------------------------------
"在"字符所占的字节长度如下:
ISO-8859-1:1
UTF-8:3
GBK:2
GB2312:2
GB18030:2
UTF-16:4
--------------------------------------
"A"字符所占的字节长度如下:
ISO-8859-1:1
UTF-8:1
GBK:1
GB2312:1
GB18030:1
UTF-16:4
"1"字符所占的字节长度如下:
ISO-8859-1:1
UTF-8:1
GBK:1
GB2312:1
GB18030:1
UTF-16:4
0 0
- java获取字节的长度
- java获取字节的长度.
- java按照字节长度获取字符串长度
- java获取一个字符串字节长度
- 获取含中文的真实字节长度
- 获取字符窜的字节长度
- iOS 获取字符串的字节长度
- javascript获取字符的字节长度
- c#获取汉字的字节长度
- NET获取汉字的字节长度
- js获取字符串的字节长度
- 获取字符串的长度(非字节长度)
- 获取字符的字节长度, 获取中英文的字符字节长度
- 获取字符串长度、字符长度、字节长度
- 获取字符串长度、字符长度、字节长度
- Java中数据类型对应的字节长度
- Java String类型数据的字节长度
- JAVA String类型数据的字节长度
- 不同计算机之间实现生产者-消费者问题
- 金蝶KIS专业版12.0登录时提示-8880
- Codeforces 55D Beautiful numbers (数位dp,状压辅助)
- 浅谈Adapter
- Exception in thread "main" java.lang.IllegalThreadStateException
- java获取字节的长度.
- 提高PHP代码质量36计
- MAC虚拟机无损扩容
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- linux基础知识
- 记录常遇到的异常 (NullPointerException,NumberFormatException,ClassCastException...)
- centos6.4搭建apache+mysql+php环境
- storm日志处理坑1
- 2014-12-12-系统退出强杀进程