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 6590201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:16:12+00:00 2026-05-25T17:16:12+00:00

I am trying to read a text file containing characters in billions. Using the

  • 0

I am trying to read a text file containing characters in billions. Using the function
contentOfFile is not working, as my application get crashed due to it.

So anybody please send me the sample code so that I get the chunks according to my requirement.Whichever i need i wanna get that one only.
please reply as soon as possible.

  • 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-25T17:16:13+00:00Added an answer on May 25, 2026 at 5:16 pm

    I’m guessing this is an iOS app. In that case, you are likely hitting the memory limit by calling contentsOfFile: because that method is trying to read the entire contents of the file into a variable (memory). Remember that on iOS your app must play nice and if it decides to consume too much memory, then the watchdog process will kill your app to save the device from rebooting (which happens because there is no disk to swap to on iOS devices).

    Have you had a look at NSFileHandle? NSFileHandle supports seeking within a text a file. With some simple iteration you can use the following to methods to seek within the file and read chunks of data:

    - (NSData *)readDataOfLength:(NSUInteger)length;
    - (void)seekToFileOffset:(unsigned long long)offset;
    

    It might look something like this. Assume pathToFile is an NSString containing the path to the text file to be read in.

    uint64 offset = 0;
    uint32 chunkSize = 1024;     //Read 1KB chunks.
    NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:pathToFile];
    NSData *data = [handle readDataOfLength:chunkSize];
    
    while ([data length] > 0)
    {
         //Make sure for the next line you choose the appropriate string encoding.
         NSString *dataString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
    
         /* PERFORM STRING PROCESSING HERE */
    
         /* END STRING PROCESSING */
         offset += [data length];
    
         [handle seekToFileOffset:offset];
         data = [handle readDataOfLength:chunkSize];
    }
    
    [handle closeFile];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a text file using fscanf.I am working in eclipse
I am trying to read some info from a text file by using windows
I'm trying to read the contents of a small text file using the common
I'm trying to have my application read through a text file and look for
I'm trying to read a text file containing the name of the image, and
I am trying to read a text file using the code (pasted below), but
I'm trying to read a text file line by line using InputStream from the
I'm trying to read a text file (using perl) where each line has several
I'm trying to read a text file, i'm using fileImputStream, and reading all the
I'm trying to read a text file (Using BufferedReader and FileReader) from my file

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.