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.youkuaiyun.com/winer2008/archive/2009/07/26/4381122.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值