Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read byte array from file in Haskell?

Tags:

haskell

When I want read bytes from a file in Java, I can do like this:

InputStream is = new FileInputStream(...);
while((int b = is.read()) != -1){
    //...analysis the bytes.
}

And how do it in Haskell? I don't see any function witch can read bytes module System.IO and Data.ByteString.

like image 264
Jacky Wong Avatar asked Dec 06 '25 03:12

Jacky Wong


1 Answers

Use readFile

import Data.ByteString(readFile)

main = do 
    content <-  Data.ByteString.readFile "path/to/file"
    print content

It read the file and print it content on screen.

like image 56
talex Avatar answered Dec 08 '25 21:12

talex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!