0

I would convert a FileInputStream to Array[Byte] in Scala 2.13 without using Apache Commons IO. How can I do that?

Riccardo Califano
  • 1,317
  • 3
  • 10
  • 19
  • 1
    Does this answer your question? [Convert InputStream to byte array in Java](https://stackoverflow.com/questions/1264709/convert-inputstream-to-byte-array-in-java) – Shankar Shastri Jul 06 '20 at 15:20
  • I guess you could make it a string and then do getBytes on it? I've personally had this same issue some days ago and I juset went with Apache Commions IO solution. val byteArray = org.apache.commons.io.IOUtils.toByteArray(inputFiles) , why do you not wanna use that? – GamingFelix Jul 06 '20 at 15:33
  • This also might work? val bis = new BufferedInputStream(new FileInputStream(fileName)) val bArray = Stream.continually(bis.read).takeWhile(-1 !=).map(_.toByte).toArray taken from: https://stackoverflow.com/questions/7598135/how-to-read-a-file-as-a-byte-array-in-scala – GamingFelix Jul 06 '20 at 15:36

0 Answers0