Reading and writing files
Factor handbook » Input and output

Prev:Streams
Next:Pathnames


Image Examples of reading and writing files

File streams:
Image
<file-reader> ( path encoding -- stream )

Image
<file-writer> ( path encoding -- stream )

Image
<file-appender> ( path encoding -- stream )


Reading and writing the entire contents of a file; this is only recommended for smaller files:
Image
file-contents ( path encoding -- seq )

Image
set-file-contents ( seq path encoding -- )

Image
change-file-contents ( ..a path encoding quot: ( ..a seq -- ..b seq' ) -- ..b )

Image
file-lines ( path encoding -- seq )

Image
set-file-lines ( seq path encoding -- )

Image
change-file-lines ( ..a path encoding quot: ( ..a seq -- ..b seq' ) -- ..b )


Utility combinators:
Image
with-file-reader ( path encoding quot -- )

Image
with-file-writer ( path encoding quot -- )

Image
with-file-appender ( path encoding quot -- )