如何将byte []数组转换为字节类型变量?

时间:2013-03-12 07:25:29

标签: android arrays byte

我正在使用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();
    }

1 个答案:

答案 0 :(得分:1)

您希望如何将字节数组转换为单个字节?这就像将事物转化为一件事。您可以尝试逐个发送数组的元素,因为它们是字节类型,但是否则我看不到如何实现您尝试的内容。