Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Haskell中从文件中读取字节数组?_Haskell - Fatal编程技术网

如何在Haskell中从文件中读取字节数组?

如何在Haskell中从文件中读取字节数组?,haskell,Haskell,当我想从Java文件中读取字节时,我可以这样做: InputStream is = new FileInputStream(...); while((int b = is.read()) != -1){ //...analysis the bytes. } 在哈斯凯尔是怎么做到的?我看不到任何可以通过TestRing读取字节模块System.IO和数据的函数。使用readFile import Data.ByteString(readFile) main = do cont

当我想从Java文件中读取字节时,我可以这样做:

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

在哈斯凯尔是怎么做到的?我看不到任何可以通过TestRing读取字节模块System.IO和数据的函数。

使用
readFile

import Data.ByteString(readFile)

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

它读取的内容是
ByteString
,这实际上是
Word8
的数组,这是命名字节的聪明方法。所以你的意思是我不需要导入
ByteString
来读取
Word8
,就像Java中的
byte
一样?最简单的检查方法是尝试,但可以,您不需要导入它。@talex prelude中的readFile读取到一个
字符串中。提问者似乎想把问题读入字节而不是字符。我认为
ByteString
是正确的。@Potato44然后应该导入适当的(
Data.ByteString
)函数。