Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XE8 C++ Builder How to open file in BINARY mode (Android and iOS)


This question is answered.


Permlink Replies: 2 - Last Post: Oct 4, 2015 4:25 PM Last Post By: Anupama Annambh...
Anupama Annambh...

Posts: 24
Registered: 1/16/15
XE8 C++ Builder How to open file in BINARY mode (Android and iOS)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 2, 2015 9:26 AM
Hi,

I am working on a multi device application (Android , iOS) and the application requires opening an image file for reading and then copying it into buffer.
The IDE is XE8 C++ builder

The files are the split version of a single YUV image and ends up as individual Y, U, V components i.e. filename.y filename.u and filename.v extensions respectively.

In Windows, the files are located on disk in the same project folder and I am able to achieve this by: *FILE * fp = fopen(filename, "rb");*
Can you please suggest what is the equivalent method or mode for Android / iOS.

For Android:
I am including the files in the APK using the Deployment Manager. And later opening the files from Internal Memory.

Option 1: Using File Handle

// Fetch the full filename path from Internal Memory
AnsiString yFilename = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"stefan_cif_flipped.y");

// Open the Yimage; file in READ mode
int yFileHandle;
yFileHandle = FileOpen(yFilename, fmOpenRead);

Open 2: Using File Stream

// Opening file using FileStreams
TFileStream *yInput = new TFileStream(yFilename, fmOpenRead);

Note: Both seem to work and return success. But the file is being opened in TEXT MODE.
How do we open a file in BINARY MODE?

I have looked for Wiki docs for days now but in vain.
Any input is greatly appreciated.

Thank you

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: XE8 C++ Builder How to open file in BINARY mode (Android and iOS)
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 2, 2015 10:29 AM   in response to: Anupama Annambh... in response to: Anupama Annambh...
Anupama wrote:

// Fetch the full filename path from Internal Memory
AnsiString yFilename =
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),
L"stefan_cif_flipped.y");

Why are you converting the filename from Unicode to Ansi? FileOpen() and
TFileStream both take a UnicodeString as input.

Note: Both seem to work and return success. But the file is being
opened in TEXT MODE.

What makes you think that?

TFileStream is just a wrapper around FileCreate/FileOpen/FileRead/FileWrite().
And no, FileOpen() does not use TEXT mode, on any platform. On Windows,
it uses CreateFile(). On other platforms, it uses the POSIX open() function,
which has no concept of text vs binary, it always operates in binary only.

How do we open a file in BINARY MODE?

You already are. Why do you think otherwise?

--
Remy Lebeau (TeamB)
Anupama Annambh...

Posts: 24
Registered: 1/16/15
Re: XE8 C++ Builder How to open file in BINARY mode (Android and iOS)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 4, 2015 4:25 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Oh! I didn't realize that.
Thank you very much for the clarification.
Also I have made changes to use UnicodeString instead.

Anu

Remy Lebeau (TeamB) wrote:
Anupama wrote:

// Fetch the full filename path from Internal Memory
AnsiString yFilename =
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),
L"stefan_cif_flipped.y");

Why are you converting the filename from Unicode to Ansi? FileOpen() and
TFileStream both take a UnicodeString as input.

Note: Both seem to work and return success. But the file is being
opened in TEXT MODE.

What makes you think that?

TFileStream is just a wrapper around FileCreate/FileOpen/FileRead/FileWrite().
And no, FileOpen() does not use TEXT mode, on any platform. On Windows,
it uses CreateFile(). On other platforms, it uses the POSIX open() function,
which has no concept of text vs binary, it always operates in binary only.

How do we open a file in BINARY MODE?

You already are. Why do you think otherwise?

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02