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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:59:11+00:00 2026-05-25T14:59:11+00:00

I want to write data to a .txt file without replacing its older contents.I

  • 0

I want to write data to a .txt file without replacing its older contents.I have moved the file from the NSMainBundle to the documents directory.I am able to write the the file by using the code

NSData *data=[NSKeyedArchiver archivedDataWithRootObject:recentMainArray];
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[myHandle seekToEndOfFile];
[myHandle writeData:data];
[myHandle closeFile];

But when i try to display the contents of the file,i don’t have any data in that.File exists in that path also.This is the following code i use to display the contents.

NSFileManager *manager = [NSFileManager defaultManager];

//filePath – > the documents directory file path

if([manager fileExistsAtPath:filePath]) {

        NSMutableArray *savedArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
        NSMutableArray *storedRecentID = [savedArray objectAtIndex:0];
        NSMutableArray *storedRecentName = [savedArray objectAtIndex:1];
        NSLog(@"ID:%@",[savedArray objectAtIndex:0]);
        NSLog(@"Name:%@",[savedArray objectAtIndex:1]);

} 
else {
        NSLog(@"file not found, save something to create the file");
}

“null” which is printed as result for those two nslogs.

Please anybody let me know a solution for this problem.FYI,i am using a simulator to test,is this creating a problem.Please suggest me a solution.I have searched a lot and i am not able to find a solution.

Thank you all in advance

  • 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-25T14:59:12+00:00Added an answer on May 25, 2026 at 2:59 pm

    Read the data into some Mutable structure (dictionary, array, string) and then append your new data into the same satring. Now write the data into the same path. So the new appended data will be written in file.

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

Sidebar

Related Questions

I have blocks of data that I want to write in a txt, or
I am trying to write data from three txt files in csv file. three
I want to write data into the file in binary form. I was trying
I want to write data to an output file and save it on a
I want to write JSON data to a text file using jQuery and PHP.
I want write a simple query which will fetch data from a table (which
i want simultaneously read and write data into file. Can i use StreamReader and
I am using ofstream() to write data into file, i want the program to
I have a BitSet and want to write it to a file- I came
I want to write a Perl Script that reads a file.txt with columns of

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.