1

I am trying to save the string in .txt file and wants to see that .txt file in Files app. It is possible to save and read the file in documents directory but I am struggling to save and see in Files app.

Your help will be appreciated.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50

1 Answers1

0

You can create the file with:

    NSString* filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* fileName = @"file.txt";
NSString* fileAtPath = [filePath stringByAppendingPathComponent:fileName];

if (![[NSFileManager defaultManager] fileExistsAtPath:fileAtPath]) {
    [[NSFileManager defaultManager] createFileAtPath:fileAtPath contents:nil attributes:nil];
}

And read it with:

NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fileName = @"file.txt";
NSString *pathDocuments = [filePath stringByAppendingPathComponent:fileName];

After having the file path then it is up to you to parse it.

icould
  • 315
  • 3
  • 9
  • Hi, here question is asked about to read and write .txt file into Files app which is in iOS 11. You are giving answer for own apps sandbox – Sachin Waje Mar 16 '18 at 12:36