Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Save and retreive text from text file

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 322
    Comment on it

    Hi all,

    If you want to save anything in text file or any kind of file than you can follow this code. This code will save text to textfile in your application directory.You can retrieve text from save file later on .

    NSError *error;
    NSString *stringToWrite = @"1\n2\n3\n4";
    NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"myfile.txt"];
    [stringToWrite writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
    

    Now file is saved as myfile.txt in your application directory and if you want to reopen that file than you can reopen your file with this code.

    NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
    NSLog(@"%@", str);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: