1-- !!! readFile test
2
3import System.IO
4import System.IO.Error
5
6source   = "readFile001.hs"
7filename = "readFile001.out"
8
9main = do
10  s <- readFile source
11  h <- openFile filename WriteMode
12  hPutStrLn h s
13  hClose h
14  s <- readFile filename
15
16  -- This open should fail, because the readFile hasn't been forced
17  -- and the file is therefore still locked.
18  tryIOError (openFile filename WriteMode) >>= print
19
20  putStrLn s
21
22  -- should be able to open it for writing now, because we've forced the
23  -- whole file.
24  h <- openFile filename WriteMode
25
26  print h
27