字串 位元組陣列 可序列化物件之間的相互轉化

2021-08-07 22:47:21 字數 1184 閱讀 8708

/**

* 把16進製制字串轉換成位元組陣列

* * @param hex

* @return

*/public static byte hexstringtobyte(string hex)

return result;

}private static byte tobyte(char c)

/*** 把位元組陣列轉換成16進製制字串

* * @param barray

* @return

*/public static final string bytestohexstring(byte barray)

return sb.tostring();

}/**

* 把位元組陣列轉換為物件

* * @param bytes

* @return

* @throws ioexception

* @throws classnotfoundexception

*/public static final object bytestoobject(byte bytes) throws ioexception,

classnotfoundexception

/*** 把可序列化物件轉換成位元組陣列

* * @param s

* @return

* @throws ioexception

*/public static final byte objecttobytes(serializable s) throws ioexception

/*** 把可序列化物件轉換成字串

* * @param s

* @return

* @throws ioexception

*/public static final string objecttostring(serializable s) throws ioexception

public static final string objecttohexstring(serializable s)

throws ioexception

public static final object hexstringtoobject(string hex)

throws ioexception, classnotfoundexception

字串 位元組陣列 字元陣列之間的轉換

package stringexample 1.字串與基本資料型別 包裝類之間的轉換 字串 基本資料型別 包裝類 呼叫相應的包裝類的pa xx string str 基本資料型別 包裝類 字串 字串過載的valueof 方法 2.字串與位元組陣列 字串 位元組陣列 字串的getbytes 位元組陣列...

字串 位元組陣列互轉

將byte轉換為string 或者將string轉換為byte author administrator public class byteorstringhelper param str 源字串轉換成位元組陣列的字串 return public static byte stringtobyte s...

C 字串到位元組陣列,位元組陣列轉整型

int num 12345 string num1 convert.tostring 12345,16 byte bytes bitconverter.getbytes num 將int32轉換為位元組陣列 num bitconverter.toint32 bytes,0 將位元組陣列內容再轉成in...