Scala: InputStream to Array[Byte]

后端 未结 11 966
臣服心动
臣服心动 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 07:06

    import scala.tools.nsc.io.Streamable
    Streamable.bytes(is)
    

    Don't remember how recent that is: probably measured in days. Going back to 2.8, it's more like

    new Streamable.Bytes { def inputStream() = is } toByteArray
    

提交回复
热议问题