hIsReadable takes a file handle and
return IO True, if the handle is readable, else IO False.
Prelude System.IO> :t hIsReadable
hIsReadable :: Handle -> IO Bool
FileUtil.hs
import System.IO main = do putStrLn "Enter file name (Including full path) to read" fileName <- getLine fileHandle <- openFile fileName ReadMode isReadable <- hIsReadable fileHandle isWritable <- hIsWritable fileHandle putStrLn $ "Is file handle readable " ++ show isReadable putStrLn $ "Is file handle writable " ++ show isWritable
$ runghc FileUtil.hs Enter file name (Including full path) to read today.txt Is file handle readable True Is file handle writable False
No comments:
Post a Comment