1

Topic: iOS Objective a C Operation with files

Couple of days I can not solve a problem. It is required to save in a file a text line, then it from there to take, and a file or to delete or clear its contents. I tried NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:@ "receipt.txt"]; But file always nil. I tried to write down in file NSData *savedata = [postDataFile dataUsingEncoding:NSUTF8StringEncoding]; [savedata writeToFile:@ "receipt.txt" atomically:YES]; and then to get NSString *str = [[NSString alloc] initWithContentsOfFile:@ "receipt.txt" encoding:NSUTF8StringEncoding error:NULL]; but str always nil. What do I do not so and how it is possible to solve a problem?

2

Re: iOS Objective a C Operation with files

Hello, robesh, you wrote: R> Couple of days I can not solve a problem. It is required to save in a file a text line, then it from there to take, and a file or to delete or clear its contents. I tried R> NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:@ "receipt.txt"]; You try to open a file in the current directory (bundle directory) which is inaccessible to record. Esteem about structure of directories of a sandbox iOS. In your case (if the file is not necessary between application launches) it is necessary to create a file in tmp, likely. Research of errors perfectly would help With these cases, errno quite works. Well also there are type methods fileHandleForUpdatingURL:error: which return an error.