[Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

zaxis z_axis at 163.com
Mon Jun 7 20:37:28 EDT 2010





Bill Atkins-6 wrote:
> 
> readFile reads the file lazily so it isn't closed until the entire
> contents have been consumed.
> 
> Try System.IO.Strict.readFile, which will read the entire file at once.
> Yes, and i can use appendFile too.
> 
> appendFile "ssqHitNum.txt" $ unwords $ [no] ++ map (\n -> show n) hitNum
> ++ ["\n"]
> 
> zaxis <z_axis at 163.com> writes:
> 
>> hitSSQ :: String -> [Int] -> IO ()
>> hitSSQ no hitNum = do
>>    let newNum = unwords $ [no] ++ map (\n -> show n) hitNum
>>    hitNums <- fmap lines $ readFile "test.txt"
>>    writeFile "test.txt" $ unlines $ hitNums ++ [newNum]
>> 
>> *** Exception: test.txt: openFile: resource busy (file is locked)
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


-----
e^(π⋅i) + 1 = 0
-- 
View this message in context: http://old.nabble.com/After-%60readFile%60%2C-why-cannot-i-%60writeFile%60----tp28793133p28812627.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list