- 论坛徽章:
- 30
|
- -module(t).
- -compile(export_all).
- -include_lib("kernel/include/file.hrl").
- start() ->
- ets:new(?MODULE,[public,named_table]),
- ets:insert(?MODULE,{t,"ini"}),
- ets:insert(?MODULE,{size,0}),
- spawn(fun()->timer() end).
- cancel(Pid) -> Pid ! cancel.
- timer() ->
- receive
- cancel ->
- void
- after 5000 ->
- do_check(),
- timer()
- end.
- do_check()->
- case file:read_file_info("t.txt") of
- {ok,Exist}->
- F = Exist#file_info.mtime,
- [{t,G}]= ets:lookup(t,t),
- case F =:= G of
- true ->
- ok;
- false ->
- [{size,O}]= ets:lookup(t,size),
- N=Exist#file_info.size,
- L = N - O,
- ets:insert(?MODULE,{t,F}),
- ets:insert(?MODULE,{size,N}),
- {ok,S}=file:open("t.txt",[]),
- {ok,C}=file:pread(S,O,L),
- io:format("NewContent:~p~n",[C])
- end;
- _->
- error
- end.
复制代码 |
|