Problem with reading bundle text file

Posts: 6
Joined: 2010.01
Post: #1
Hi all,

I have some text files contain level data, i'm able to get the path of bundle file, but i couldn't success to read it in both objective-c or c++ ways. Cry

Here is my code:

- (void) loadLevel: (NSString*) levelFilename
    NSString *filePath = [[[NSBundle mainBundle] resourcePath]
    const char *filename = [filePath UTF8String];
    map->loadMap(filename, blocks);

        /***** I'm new to objective-c, i copied this code from apple document *****
         NSString *myText = [NSString stringWithContentsOfFile:filePath];
     NSError *error;
     NSString *myText = [[NSString alloc] initWithContentsOfFile:filePath                                                            
     NSLog(@"%@", myText);  // it shows NULL here...

void Map::loadMap(const char *filename, bool blocks[16][16])
    cout << "Filename: " << filename << endl;
    ifstream infile(filename);    
        cout << "Error: " << filename << " can't open!" << endl;
    string test;
    while(getline(infile, test))
        cout << test << endl;
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
Since you know where the problem is, inspect the file path you're getting back and check to see if your file is in that location.
Quote this message in a reply
Posts: 6
Joined: 2010.01
Post: #3
Thanks for replied, i just checked the .app file, and my text file isn't there.
I added the text file in Resource folder already, how come it didn't bundle with the app?

Do i have to set anything?
Quote this message in a reply
⌘-R in Chief
Posts: 1,277
Joined: 2002.05
Post: #4
Check if it's actually in the Copy Resources build phase in the app Target.
Quote this message in a reply
Posts: 6
Joined: 2010.01
Post: #5
i deleted the files and recopy them few times, and finally the problem is solved.

Thanks for all the replies!!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Reading a ".puz" file tcIgnatius 0 4,756 Jul 5, 2010 02:49 PM
Last Post: tcIgnatius
  Bundle Identifier used by another app Bersaelor 3 5,467 May 7, 2010 01:01 PM
Last Post: Bersaelor
  Save game state using Property list or Text File? Graphic Ace 2 5,023 Apr 6, 2009 03:48 AM
Last Post: Graphic Ace