Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1043231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:38:05+00:00 2026-05-16T15:38:05+00:00

I am reading a file in iphone app. Its Works Fine. NSArray *paths =

  • 0

I am reading a file in iphone app. Its Works Fine.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSLog(@"%@",documentsDirectory);
    NSString *fileName = [NSString stringWithFormat:@"%@/test.txt",documentsDirectory];
    NSLog(@"%@",fileName);
    NSString *content = [[NSString alloc] initWithContentsOfFile:fileName
                                                    usedEncoding:nil
                                                           error:nil];
    NSLog (@"%@",content);
}

works good when i am using filename as test.txt

But when i add another file in the resource suppose test1.txt then NSLog(@"%@",documentsDirectory) and NSLog(@"%@",fileName) shows the right result. But

NSLog (@"%@",content); prints null in the log. So what is the reason?

I am printing detail error and it prints

NSFilePath = "/Users/sam-xxx/Library/Application Support/iPhone Simulator/3.2/Applications/51197946-6042-4A90-AA39-F07F8A649308/Documents/test1.txt";
    NSUnderlyingError = Error Domain=NSPOSIXErrorDomain Code=2 "Operation could not be completed. No such file or directory";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:38:06+00:00Added an answer on May 16, 2026 at 3:38 pm

    It would be best here to check to see if an error is returned:

    NSError *error;
    NSString *content = [[NSString alloc] initWithContentsOfFile:fileName
                                                    usedEncoding:nil
                                                           error: &error];
    if (error) NSLog(@"Error !: %@", [error localizedDescription]);
    

    That will (hopefully) give you a clue as to whats going on.

    (Edited to give example bundle resource usage as the file is in the bundle not the Documents directory).

    Docs for NSBundle are here: NSBundle Documentation

    You have 2 choices, the one you suggest:

    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
    

    Which will return the Bundle resource directory with the filename appended to that path.

    Personally I prefer the pathForResource:ofType: method:

    NSString *filename = [[NSBundle mainBundle] pathForResource: @"test1" ofType: @"txt"];
    

    As this will not only tell you if the file exists (returns nil if it does not) but will also search the localisation directories if you have them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Aha! I actually haven't used the "fixed" positioning property much,… May 17, 2026 at 1:57 am
  • Editorial Team
    Editorial Team added an answer If the applications are on the same server. i would… May 17, 2026 at 1:57 am
  • Editorial Team
    Editorial Team added an answer You can use a QUOTE field to do so. The… May 17, 2026 at 1:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to parse and XML file in an iPhone app without going to
I am reading data from an IPhone App that uses http POST to transfer
I'm making an iPhone app where I want to save state of the Application.
In my dictionary IPhone app I need to save an array of strings which
I'm writing a data collection app for the iPhone, and want to be able
I've been reading through this tutorial for using a SQLite database within an iPhone
I am writing an iPhone app – a client for some social network. The
The iphone app I am creating has an array of commonly used settings. These
I'm working on a phonegap iPhone app which downloads content from the network in
I've got an iPhone app that need to be localized. No problem with strings,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.