I am trying to read the contents of a file, turn the text to upper-case and then write it back.
Here is the code I had written:
import System.IO
import Data.Char
main = do
handle <- openFile "file.txt" ReadWriteMode
contents <- hGetContents handle
hClose handle
writeFile "file.txt" (map toUpper contents)
return ()
However, this writes nothing to the file, in fact, it even clears it.
I made some changes:
main = do
handle <- openFile "file.txt" ReadWriteMode
contents <- hGetContents handle
writeFile "file.txt" (map toUpper contents)
hClose handle
return ()
However, I get the error resource busy (file is locked). How can I get this working and why it didn't work in both cases?