withFile -package:htaglib

The computation withFile path mode action opens the file and runs action with the obtained handle before closing the file. Even when an exception is raised within the action, the file will still be closed. This is why withFile path mode act is preferable to
openFile path mode >>= (\hdl -> act hdl >>= hClose hdl)
See also: bracket
withFile name mode act opens a file like openFile and passes the resulting handle to the computation act. The handle will be closed on exit from withFile, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act.
Unlifted version of withFile.
Open a file in binary mode, and pass its Handle to a provided computation. The Handle will be automatically closed when the computation returns. This computation throws IOError on failure. See “Classifying I/O errors” in the System.IO.Error documentation for information on why the failure occured.
Acquire a Handle within MonadSafe The file is opened in text mode. See also: withBinaryFile
Create a temporary file with the given contents and execute the given action. The file is removed after the action has completed.
Like withFile, but sets the file encoding to UTF-8, regardless of the current locale.
withFile name mode act opens a file using openFile and passes the resulting handle to the computation act. The handle will be closed on exit from withFile, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act. Pre-release
withFile name mode act opens a file and passes the resulting handle to the computation act. The handle is closed on exit from withFile, whether by normal termination or by raising an exception. If closing the handle raises an exception, then that exception is raised by withFile rather than any exception raised by act. The file is opened in binary mode as encoding, decoding, and newline translation can be handled explicitly by the streaming APIs. The file is opened without buffering as buffering can be controlled explicitly by the streaming APIs. Pre-release
Like withFile in base package but using Path instead of FilePath. Use hSetBinaryMode on the handle if you want to use binary mode.
Opens a file, manipulates it with the provided function and closes the handle before returning. The Handle can be written to using the hPutStr and hPutStrLn functions. withFile is essentially the bracket pattern, specialized to files. This should be preferred over openFile + hClose as it properly deals with (asynchronous) exceptions. In cases where withFile is insufficient, for instance because the it is not statically known when manipulating the Handle has finished, one should consider other safe paradigms for resource usage, such as the ResourceT transformer from the resourcet package, before resorting to openFile and hClose.
withFile filepath mode act opens a file using the mode and run act. the by-product handle will be closed when act finish, either normally or through an exception. The value returned is the result of act@
Run an action on a file. The Handle is automatically closed afther the action.
Like withFile, but takes a PlatformPath instead of an OsPath.
Acquire a file handle and perform an I/O action. The file will be closed on exit or when this I/O action throws an exception.
Wrapper around withFile
Open a file and perform an action on its handle
withFileBlocking name mode act opens a file like openFileBlocking and passes the resulting handle to the computation act. The handle will be closed on exit from withFileBlocking, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act.