如何在Haskell中从文件中读取字节数组?
当我想从Java文件中读取字节时,我可以这样做:如何在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
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
)函数。