I would convert a FileInputStream to Array[Byte] in Scala 2.13 without using Apache Commons IO. How can I do that?
-
1Does this answer your question? Convert InputStream to byte array in JavaShankar Shastri– Shankar Shastri2020-07-06 15:20:52 +00:00Commented Jul 6, 2020 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– GamingFelix2020-07-06 15:33:10 +00:00Commented Jul 6, 2020 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: stackoverflow.com/questions/7598135/…GamingFelix– GamingFelix2020-07-06 15:36:12 +00:00Commented Jul 6, 2020 at 15:36
Add a comment
|