Reputation: 3494
I need to delete the contents of a .txt
file and I don't know how to delete the full text.
The file is in my mainBundle
. I can access the file but I can't find the command to delete the text from inside it.
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
NSString* path = [[NSBundle mainBundle] pathForResource:@"UserData"
ofType:@"txt"];
NSString* content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
Upvotes: 0
Views: 1178
Reputation: 996
The proper way is to make a copy of your text file from the app bundle into the user's Documents folder and make whatever changes you want there. Preferably, you should do this the first time your user launches your app.
The contents of the app bundle is read-only and should never be modified.
Upvotes: 0
Reputation: 180987
The files in the mainBundle are not writable with a non jailbroken iPhone, so erasing the contents of the file in its current location cannot be done.
Upvotes: 1
Reputation: 47104
You shouldn't do this on iOS in production apps. The bundle is signed, so changing its contents will make the app stop working.
Upvotes: 1
Reputation: 425
try creating a new file with the same name if it is not ready- only file ..
Upvotes: 1