[erlang-questions] File IO
Gleb Peregud
gleber.p@REDACTED
Fri May 16 20:42:06 CEST 2008
I haven't checked it myself, but i think you sould close file when
done writing (to force erlang/OS to flush IO). Add
file:close(WriteDescr). at the end of the function
On 5/16/08, Vlad12 <vsarpe@REDACTED> wrote:
>
> Hi, I am trying to create an erlang program that takes a binary trace file
> and converts it into normal text.
>
> My question is, how can i write a bunch of terms to a file. Here is how my
> code looks like, but using different terms (in string representation) and
> this compiles, runs, but produces an empty file. Am I missing something
> important?
>
> -module(test).
> -export([write/1]).
> -import(lists,[foreach/2]).
>
> write(WriteFile) ->
> {ok, WriteDescr} = file:open(WriteFile, [raw, write]),
> Terms = ["one","two","three","four","five"],
> Writer=fun(Term) -> file:write(WriteDescr, Term) end,
> lists:foreach(Writer, Terms).
>
> Vlad.
> --
> View this message in context:
> http://www.nabble.com/File-IO-tp17281272p17281272.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
--
Gleb Peregud
http://gleber.pl/
Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong
More information about the erlang-questions
mailing list