Open file for reading and writing?


#1

Hi,

Example:

File f("test.txt");
FileInputStream* in = f.createInputStream();
FileOutputStream* out = f.createOutputStream();

and the after every write operation call:

out->flush();

Is this ok?
What about File/InputStream getSize()/getTotalLength() methods?

Thanks, bye


#2

Hmm… Unlikely to work perfectly, because the input stream might lose track of changes to the file’s size and stop reading beyond a certain point.


#3

You can try this “virtual int OutputStream::writeFromInputStream ( InputStream & source, int maxNumBytesToWrite)” and let juce do all the work for you.

Or If you want to read and write data selectively, you can use " setPosition (int64 pos)" or “int64 getPosition ()” to seek around and "int read (void *destBuffer, int maxBytesToRead) " to actually read the data to a buffer, contents of which you can transfer to another file.