Not able to read a file just created

N

Naresh Ramaswamy

hi,

My Ruby code is as follows
In a class
One method creats and writes (write_data) one/more files by reading data
from another file.
Another method reads (read_data) these files and perform some action.

Observed that I am not able to read contents of files just created
(though I can see data in those files as expected) when I call these
functions one after the other.

Where as if I run only the 'Read' method I am able to read the files.
There seems to be no error in the code, but I feel that since the file
is just getting created it is not allowing me to do any action on that
unless my program is closed and a new program started.

Is there any solution for this? Attached the code for your view.

Naresh
 
C

Choi, Junegunn

Try calling File#flush method after writing to the newly created file,
so that the buffered data is flushed to OS. Or you can even call
File#fsync to ensure that the data is actually written to disk.
 
L

Louis-Philippe

[Note: parts of this message were removed to make it a legal post.]

If these tricks don't do, try closing the writing filehandle before opening
the reading one, that does it for me.

L-P
 
N

Naresh Ramaswamy

Louis-Philippe said:
If these tricks don't do, try closing the writing filehandle before
opening
the reading one, that does it for me.


It did work for me too, thanks you very much.

Naresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top