转自:http://blog.csdn.net/linlzk/article/details/6566124 Java与其他语言编写的程序进行tcp/ip socket通讯时,通讯内容一般都转换成byte数组型,java在字符与数组转换也是非常方便的: 1.将字符转换成byte数组 String  str = "罗长";     byte[] sb = str.getBytes(); 2.将byte数组转换成字符 byte[] b={(byte)0xB8,(byte)0xDF,(byt…
字节数组byte[]与图片image之间的转化 字节数组转换成图片 public static Image byte2img(byte[] buffer) { MemoryStream ms = new MemoryStream(buffer); ms.Position = 0; Image img = Image.FromStream(ms); ms.Close(); return img; } 图片转化为字节数组 public static byte[] byte2img(Bitmap Bi…
C#中字节数组byte[]和字符串string类型的相互转换: string转byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str ); byte[]转string: string str = System.Text.Encoding.Default.GetString ( byteArray );…
java中数组.集合.字符串之间的转换,以及用加强for循环遍历: @Test public void testDemo5() { ArrayList<String> list = new ArrayList<String>(); list.add("甲乙1"); list.add("甲乙2"); list.add("甲乙3"); list.add("甲乙4"); // 把集合转换为字符串,并用“ ,”…
转换过程主要使用到System.Text.Encoding命名空间下的类 1. 字符串转换成字节数组byte[]: string str = "This is test string"; byte[] byteArray = System.Text.Encoding.Default.GetBytes(str); 2.字节数组换成字符串: byte[] byteArray = 通过某种方式获取到的字节数组 string str = System.Text.Encoding.Default…
在Java中有8中基本数据类型,分别为: 整型: byte.short.int.long 浮点型:float.double 布尔型:boolean 字符型:char. byte:    8位,  封装类:Byte 1byte = 8bit;   -128~127之间所有的整数 "位"是byte,"字节"是bit 2个字节表示一个字符. 声明举例:byte a = 1; short:   16位,短整型,封装类Short,范围在(-2^15) ~ (2^15)-1 之…
在数据传输过程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键.例如:JSON字符串:var str1 = '{ "name": "cxh", "sex": "man" }';JSON对象:var str2 = { "name": "cxh", "sex": "man"…
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package test.util; /** * * @author Administrator */ public class StringUtil { public StringUtil() { } /** * 将指定byte数组以16进制的形式打印到控制台 * @param hint String…
基本数据类型:不支持面向对象的编程机制(没有属性和方法),即不支持面向对象,之所以提供8中基本数据类型,是为了方便常规数据的处理. 包装类:通过包装类可以将基本数据类型的值包装为引用数据类型的对象,使其具有面向对象的特征. 下面是8中基本数据类型及其对应的包装类: 基本类型对应的包装类 基本类型 包装类 byte Byte char Character int Integer short Short long Long float Float double Double boolean Bool…
import org.apache.commons.codec.binary.Base64; public class UtilHelper { //base64字符串转byte[] public static byte[] base64String2ByteFun(String base64Str){ return Base64.decodeBase64(base64Str); } //byte[]转base64 public static String byte2Base64StringFu…