Reading text files problem. (cocos2d-x 3.0alpha)

Hello!

I have been trying to load a text file from the mainbundle but I can’t get it to work on an actual iOS device. Here is my procedure when I add files:

  • I drag the folder containing my files (located in the same place as the Resource folder, the project “Root” with all the different platform folders) to my project tree and select/check…
  • “Copy items to destination group’s folder (if needed)”
  • “Create folder references for any added folders”
  • “Add to targets”

This creates a blue folder named “Meshes” in the project tree and copies the folder to the proj.ios project folder, all is well so far. When trying to load a text file from the folder I use:

fullPath= CCFileUtils::getInstance()->fullPathForFilename("Meshes/testObj.obj");

The path returned can be used to read my object without any problems in the simulator. It doesn’t matter if I have “Meshes/” at the beginning or leave it out. When I try to run it on an iOS device the path is set in a similar manner but the file does not open. Seems it can’t find my file for some reason. The resulting path on an iOS device looks like this:

"/var/mobile/Applications/54E4328D-3CEF-.../proj-x.app/Meshes/testObj.obj"

I have opened the target app in finder and looked at its contents to be sure the files are present in the package… and as far as I can tell they are (located in a “Meshes/…” folder inside the package). Should I be using some other method when obtaining the filename?

Any help appreciated, thanks for reading.

[edit]
I load my text file with fstream, like this:

std::fstream file; file.open(fileName); if(file.is_open()){ ...

The if-condition returns true in the simulator and false on my device.
[/edit]

Hi,

Read this post:

And see if it helps you

Massimo

Thank you, got it to work. Seems I need to use getFileData() to get to my text file. I thought fstream would work on iOS?

I am not sure if it is a good idea to post under here but I also got a question under reading text file in cocos2d-x 3.0 alpha (I am now in alpha1)

I am reading some xml and plist files by the following code

long nSize = 0;
unsigned char *pBuffer = FileUtils::getInstance()->getFileData(_path, "rt", &nSize);

I got it run under iOS (7.0.4) and android (4.0.3) actual devices. It works but occasionally the file will be failed to load in.
iOS: About 1 time out of 10 times
Android: About 2-3 times out of 10 times

Is there any restrictions in loading files like not suggested to load the same file for several times in short etc.?

Thanks