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

  • SEARCH
  • Home
  • 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 6002849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:02:14+00:00 2026-05-23T01:02:14+00:00

I´m simply trying to read a text file on a server. For testing the

  • 0

I´m simply trying to read a text file on a server. For testing the file is local at the moment. The code looks like:

        NSString *pathToLocalFile = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/dataVersion.txt"];
NSURL *URLToLocalFile = [[NSURL alloc]initFileURLWithPath:pathToLocalFile];

if (![[NSFileManager defaultManager] fileExistsAtPath:pathToLocalFile]) {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager createFileAtPath:pathToLocalFile contents:nil attributes:nil];
}

NSError *err = nil;
//NSURL *url = [[NSURL alloc] initWithString:@"http://stackoverflow.com/tags"];
    //using url also doesn't work
localFile = [[NSFileHandle alloc]fileHandleForReadingFromURL:URLToLocalFile error:&err];
localFileData = [localFile readDataToEndOfFile];

The Problem is located here

[[NSFileHandle alloc]fileHandleForReadingFromURL:URLToLocalFile error:&err]; 

It always throws the following exception:

**NSInvalidArgumentException**, reason: **-[NSConcreteFileHandle fileHandleForReadingFromURL:error:]: unrecognized selector sent to instance.**  

The URLToLocalFile object seems to be okay.

What am I doing wrong here?

  • 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-23T01:02:15+00:00Added an answer on May 23, 2026 at 1:02 am

    It’s a class method, you do not need to alloc an instance. Do this:

    [NSFileHandle fileHandleForReadingFromURL:URLToLocalFile error:&err];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read from a simple text file that looks like this: 11
I have some simple text file. I am trying to read that file contents
I am trying to read a simple text file into a String. Of course
I'm trying to read from a simple text file. Whenever I run the program
I'm trying to read a simple unicode (UTF-16) text file with just some numbers
I'm trying to import a text file to simply display in a textview using
I'm simply trying to assign a UITextField.text to an NSString in my object. The
Good times! My Android app is trying to read simple text file, using usual
I'm trying to read a simple text file shown below with the Scanner class
I have a really simple XML file that I'm trying to read, but I

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.