【发布时间】:2018-08-07 14:24:39
【问题描述】:
我检查了doesFileExist filePath 但是
我如何仅在文件存在时使用handle <- openFile filePath ReadMode
或者当文件不存在时如何获取默认字符串?
getFileContent filePath = do
handle <- openFile filePath ReadMode
content <- hGetContents handle
return content
main = do
blacklistExists <- doesFileExist "./blacklist.txt"
let fileContent = if not blacklistExists
then ""
else getFileContent "./blacklist.txt"
putStrLn fileContent
【问题讨论】: