Jacky Wong
Jacky Wong

Reputation: 521

How to read byte array from file in 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.

Upvotes: 3

Views: 1330

Answers (1)

talex
talex

Reputation: 20542

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.

Upvotes: 2

Related Questions