ファイルにデータを書き込むには?
ファイルにデータを書き込むには、IFile インターフェイスの IFILE_Write 関数を使用します。 IFILEMGR_OpenFile 関数のオープン モードに _OFM_READWRITE や _OFM_CREATE を指定してファイルをオープンし、 IFILE_Write 関数を使用してファイルにデータを書き込みます。このとき、.mif ファイルでファイル アクセスを許可する必要があります。
SophiaFramework では、 SFBFile::Write 関数を使用します。
[ BREW API のみを使用したコード ]
//
// ファイルにデータを書き込みます。
//
IShell* shell = app->a.m_pishell;
IFileMgr* filemgr;
IFile* file;
char buffer[] = "If you didn't know about the FRAMEWORK for BREW,"
" the development of your products will be in the deadline.";
// IFileMgr インターフェイスを作成します。
ISHELL_CreateInstance(shell, AEECLSID_FILEMGR, (void*)&filemgr);
// ファイルをオープンします。
file = IFILEMGR_OpenFile(filemgr, "sample.txt", _OFM_CREATE);
// ファイルへデータを書き込みます。
IFILE_Write(file, buffer, sizeof(buffer) - 1);
// ファイルをクローズします。
IFILE_Release(file);
// IFileMgr インターフェイスを破棄します。
IFILEMGR_Release(filemgr);
[ SophiaFramework を使用したコード ]
// // ファイルにデータを書き込みます。 // SFBFileMgrSmp filemgr; SFBFileSmp file; AChar buffer[] = "If you didn't know about the FRAMEWORK for BREW," " the development of your products will be in the deadline."; // SFBFileMgr インスタンスを作成します。 filemgr = SFBFileMgr::NewInstance(); // ファイルをオープンします。 file = filemgr->OpenFile("sample.txt", _OFM_CREATE); // ファイルへデータを書き込みます。 file->Write(buffer, sizeof(buffer) - 1);









