importPour l'utiliser : import System.File
System.File — reading and writing whole files
Synopsis
data FileError
= NotFound Path
| PermissionDenied Path
| AlreadyExists Path
| NotAFile Path
| IOError String
What can go wrong with a file operation.
NotFound
the path does not exist
PermissionDenied
not allowed to read/write it
AlreadyExists
it already exists (e.g. createDir)
NotAFile
expected a file, found something else
IOError
any other failure, with a message
ioError : String -> FileError
A plain IO error from a message (no path), for handle-based operations.
classify : Path -> String -> FileError
readFile : Path -> Result FileError String with FileRead
Read a whole file as a string. readFile (path "notes.txt") is Ok "<contents>", or Error (NotFound …).
writeFile : Path -> String -> Result FileError () with FileWrite
Write a string to a file, replacing any existing contents.
appendFile : Path -> String -> Result FileError () with FileWrite
Append a string to the end of a file (creating it if needed).
exists : Path -> Bool with FileRead
isFile : Path -> Bool with FileRead
Does this path exist and is it a regular file?
isDir : Path -> Bool with FileRead
Does this path exist and is it a directory?
fileSize : Path -> Result FileError Nat with FileRead
The size of a file in bytes.
readLines : Path -> Result FileError (List String) with FileRead
Read a file and split it into lines.
writeLines : Path -> List String -> Result FileError () with FileWrite
Write a list of lines to a file, one per line (each followed by a newline).
readFileOr : String -> Path -> String with FileRead
Read a file, falling back to a default string if it can't be read. A convenience for when you don't want to handle the error explicitly.