语言

Menu
Sites
Language
File reading/writing

Hi,

I need to use file to read from and write in it some data. 

It's look as:

buf.Construct(BUFFER_SIZE_MAX);

// something push in buf

infoFile.Construct(App::GetInstance()->GetAppDataPath() + L"user_game_info.txt", "w+");

r = infoFile.Write(buf);

// ...

r = infoFile.Seek(FILESEEKPOSITION_BEGIN, 0);

//...

r = infoFile.Read(buf);

//...

App is run successfully only before reading file, trying to read file I got exception with "E_END_OF_FILE"  name and I don't understand why so repeats again, and again.

Also I want to ask about this created file location on emulator, where it is? Needed to root? How it may be done?

With much regards.

 

响应

5 回复
Alex Ashirov

Hi,

I have just tried the following code on Tizen 2.2.1 and it works fine:

     String input = "asdadasadaasdasd";
     String output;

     File infoFile;
     infoFile.Construct(App::GetInstance()->GetAppDataPath() + L"user_game_info.txt", "w+");

     result r = infoFile.Write(input);

     r = infoFile.Seek(FILESEEKPOSITION_BEGIN, 0);

     r = infoFile.Read(output);

     AppLog("%ls", output.GetPointer());

As you can see I use String as a buffer, but you use ByteBuffer. Probably something wrong is with your buffer.

Anatoly Krasnovsky

Thanks for your answer. When string used in this sample it work, but when after I'm write data in file and terminate app, all data in file losted and next opening get empty file.

Alex Ashirov

Hi,

You can try to add

result r = infoFile.Flush();

after

result r = infoFile.Write(input);

Alex Ashirov

Hi,

You can find your file on emulator at /opt/apps/<your app Id>/data/ folder. Please note that you need root privileges for that. Follow the steps below to output your file content in console window:

-Run command prompt

-Go to \tizen-sdk\tools folder

Execute “sdb -e root on”

Execute “sdb -e shell”

Execute “cat /opt/apps/<your app Id>/data/user_game_info.txt”