我試圖使用webservice獲取圖像並保存到SD卡。該文件保存但我無法打開文件。一旦我打開文件它說「無法加載圖像」。以下是我的代碼。文件沒有正確保存
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
test = response.toString();
Blob picture = org.hibernate.Hibernate.createBlob(test.replaceAll("-", "").getBytes());
String FILENAME = "voucher1.jpg";
File root = Environment.getExternalStorageDirectory();
FileOutputStream f = new FileOutputStream(new File(root, FILENAME));
InputStream x=picture.getBinaryStream();
int size=x.available();
byte b[]= new byte[size];
x.read(b);
f.write(b);
f.close();
請幫忙。謝謝
測試內容是什麼,爲什麼要用''替換' - '? – njzk2 2012-02-22 09:43:41
它是一個字節[],我將其轉換爲webservice中的字符串並在此處返回值。我替換' - '的原因是因爲當我檢查測試字符串..默認情況下是' - '... – 2012-02-22 09:46:41
這可能是一個問題。 byte [] - > String - > byte []不起作用,如果您使用不同的編碼,我很可能。另外,創建Blob的意義何在?如果你刪除所有的連字符,你會丟失文件的一部分 – njzk2 2012-02-22 13:37:47