Java String 和 byte[] 之間的相互轉換


  String   str   =   "abc"; 
  byte[]   b   =   str.getBytes(); 
  for   (int   i   =   0,   size   =   b.length;   i   <   size;   i++) 
      System.out.println((char)b[i]);  

  byte[]   a   =   new   byte[2]; 
  a[0]   =   (byte)0xb0; 
  a[1]   =   (byte)0xa1; 
  
  String   str   =   new   String(a);

 

 

//******************************************************Oracle blol 類型轉換

blob字段
java中用 byte[]
xx.hbm.xml中 用 <property name="xx" type="binary" lazy="true">

 

配置文件寫成java.sql.Blob類型
程序裏這寫:
worker.setPhoto(Hibernate.createBlob(new byte[1]));
SerializableBlob  sb = (SerializableBlob ) worker.getPhoto();
java.sql.Blob wrapblob = sb.getWrappedBlob();
oracle.sql.BLOB blob = (oracle.sql.BLOB) wrapblob;
OutputStream out = blob.getBinaryOutputStream(); 
byte [] buf=new byte[(int)in.available()];
這樣就轉成了字節數組了

 

 

http://blog.csdn.net/winer2008/archive/2009/07/26/4381122.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章