BFile

A BFile lets you read and write the data portion of a file. It does this by implementing the Read() / Write() and ReadAt() / WriteAt() functions that are declared by the BPositionIO class.

Initializing and Opening

When you construct (or otherwise initialize) a BFile, the file is automatically opened. The file is closed when you re-initialize or destroy the object.

At each initialization, you’re asked to supply an “open mode” value. this is a combination of flags that tells the object whether you want to read and/or write the file, create it if it doesn’t exist, truncate it, and so on.

You can also initialize a BFile, and create a new file at the same time, through BDirectory’s CreateFile() function. In this case, you don’t have to supply an open mode—the BFile that’s returned to you will automatically be open for reading and writing. (You are asked if you want the creation to fail if the named file already exists.)