【发布时间】:2016-07-07 13:58:13
【问题描述】:
有人能帮我看看我的程序出了什么问题吗?当我尝试运行以下程序时,我收到以下错误消息:
hSetFileSize: 无效参数(无效参数)
import System.IO
main = do
putStrLn "Enter file name (Including full path) to read"
fileName <- getLine
handle <- openFile fileName ReadMode
sizeBeforeTrunc <- hFileSize handle
content <- readFile fileName
putStrLn $ "Size of the file Before truncation is " ++ (show sizeBeforeTrunc) ++ " bytes"
putStrLn $ "Content of the file is " ++ content
putStrLn "**************************************"
let n = sizeBeforeTrunc `div` 2
putStrLn $ "Truncating file to " ++ (show n) ++ " bytes"
info1 <- hSetFileSize handle (toInteger 10)
putStrLn $ show info1
sizeAfterTrunc <- hFileSize handle
putStrLn $ "Size of the file After truncation is " ++ (show sizeAfterTrunc) ++ " bytes"
putStrLn $ "Content of the file is " ++ content
hClose handle
【问题讨论】: