咦用FileInputStream就可以达到你的要求呀!
byte[] b=new byte[10000000];//够用了
FileInputStream fis=new FileInputStream("xxx.jpg");
int len=fis.read(b);//读入内容,len为文件大小
好了现在b数组中从0到len的数据就是xxx.jpg的2进制数据
byte[] b=new byte[10000000];//够用了
FileInputStream fis=new FileInputStream("xxx.jpg");
int len=fis.read(b);//读入内容,len为文件大小
好了现在b数组中从0到len的数据就是xxx.jpg的2进制数据
public byte[] getBlob(String tableName, String blobField, String strPK) throws Exception
{ //由于使用连接池时存取blob/clob有问题,这里使用jdbc连接
byte byteImage[] = null;
Connection newConn = DAO.connectJDBC();
Statement stmt1 = null; stmt1=newConn.createStatement();
String tmpsqlstr="SELECT "+blobField+" FROM "+tableName+" WHERE "+strPK;
ResultSet tmprlt=stmt1.executeQuery(tmpsqlstr);
if(tmprlt.next()){
if(bOracle){
BLOB blob = ((OracleResultSet)tmprlt).getBLOB(blobField) ;
if( blob != null ){
InputStream is = blob.getBinaryStream();
//care is.available is undefined. should use blob.length();
int nCount = (int)blob.length();
byteImage = new byte[nCount];
is.read( byteImage );
is.close();
}
}
else if(bSQL){
InputStream is = tmprlt.getBinaryStream(blobField);
//care is.available is undefined. should use blob.length();
//int nCount = (int)blob.length();
byteImage = new byte[is.available()];
//if(byteImage==)
is.read( byteImage );
is.close();
//byte[] btt=tmprlt.getBytes(blobField);
//byteImage=btt;
/*Blob blob=tmprlt.getBlob(blobField);
if( blob != null )
{
InputStream is = blob.getBinaryStream();
//care is.available is undefined. should use blob.length();
int nCount = (int)blob.length();
byteImage = new byte[nCount];
is.read( byteImage );
is.close();
}*/
}
}
tmprlt.close();
stmt1.close();
newConn.close();
return byteImage;
}
可是我现在想要的是OBJECT型,用new Object(fis);好象不行啊?
谢谢在帮忙!