小编Sel*_*yst的帖子

如何关闭haskell中的文件

我有一个haskell问题...我在haskell中打开一个文件,之后我想在该文件中添加一些文本.

ame :: IO ()

ame = do
    putStr "Enter the file name: "
    name <- getLine
    file <- readFile name
    putStrLn "Do you want to add new records? "
    question <- getLine
    if question == "yes" then do
        putStrLn "Enter your records:"
        newRec <- getLine
        file <- writeFile name (file ++ newRec)

        putStrLn "a"
    else
        putStr "b"
Run Code Online (Sandbox Code Playgroud)

这是我的代码.当我想在我的文件中添加(写入)新内容时,我收到此错误..."openFile:resource busy(file is locked)".我怎么能解决这个问题?我被告知这是因为我没有关闭文件..但我怎么能关闭它?

haskell file

3
推荐指数
1
解决办法
667
查看次数

标签 统计

file ×1

haskell ×1