reading and writing text file

Wiger Ulf ulf.wiger@REDACTED
Sat Aug 2 12:08:00 CEST 2003


You can either use file:read_file() and binary_to_list(), followed by
string:tokens(List, "\n") -- which will give you a list of strings, one for
each
line of text in the file -- or use io:get_line(FileDescr,'') to read one
line
at a time from the file.

(regexp:split() will also work, but in this case, I think string:tokens/2 is
better.)

Note that reading one line at a time from the file will give better
memory characteristics.

/Uffe

----- Original Message -----
From: "Jilani Khaldi" <jilani.khaldi@REDACTED>
To: <erlang-questions@REDACTED>
Sent: den 1 augusti 2003 23:54
Subject: reading and writing text file


> Hi All,
> I have a file text "/erlang/eng.txt" and I want to read it; I have tried
> file:file_read and file:binary_to_list but the result is a file full of
> "\n".
> Is there a way to get it as a list of strings?
> Example:
> myfile.txt has these lines:
>
> Italy, Rome
> France, Paris
> England, London
>
> Now I want to chane these lines in:
>
> Italia, Roma
> Francia, Parigi
> Inghilterra, Londra
>
> and save them in "/erlang/ita.txt"
>
> I have tried many ways but in vain.
>
> Thanks!
>
> jk
>




More information about the erlang-questions mailing list