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.
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.
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.