Scala: InputStream to Array[Byte]

后端 未结 11 1049
臣服心动
臣服心动 2021-02-02 06:01

With Scala, what is the best way to read from an InputStream to a bytearray?

I can see that you can convert an InputStream to char array

Source.fromInput         


        
11条回答
  •  感动是毒
    2021-02-02 06:56

    We can do it using google API ByteStreams

    import com.google.common.io.ByteStreams
    

    pass the stream to ByteStreams.toByteArray method for conversion

    ByteStreams.toByteArray(stream)
    

提交回复
热议问题