我正在使用Android。我從圖像文件中獲取字節數組。我的要求是發送一個字節類型變量到服務器,而不是字節數組。如何將byte []數組轉換爲字節類型變量?
但我得到字節數組,然後我想將該字節數組轉換爲字節變量。
我的代碼是這樣
InputStream in = getContentResolver().openInputStream(selectedImageUri);
byte[] imageData = readBytes(in);
byte bytedata = // here I want get the bytes from imageData array
public byte[] readBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
// and then we can return your byte array.
return byteBuffer.toByteArray();
}
你可以將它轉換成字符串bytearay.toString();並通過網絡 – Pragnani 2013-03-12 07:27:41
發送它,如果您可以發送一個字節,請嘗試通過網絡逐個發送字節流。 – 2013-03-12 09:08:25