简体   繁体   中英

iphone NSFilemanager not creating file

I'm using NSFileManager to create a file at a specified path with text view contents. I'm using following code

[[NSFileManager defaultManager] createFileAtPath:saveFileName contents:[[tView text] dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];

But the problem is that, its creating file with no contents. I'm sure that text contents are not nil. How can I check and confirm that data is written into file.

Some suggestions:

  1. Capture the BOOL return of the line to make sure it is completing.
  2. Log the value of [tView text] to make sure it is not empty.
  3. ASCII encoding can cause problems these days. Try NSUTF8StringEncoding or NSUTF16StringEncoding .

Localization may be a problem with plain ASCII encoding because ASCII does not handle multibyte character encodings.

Well, I know it's few months late, but you're sending NSString instead of NSData to the contents: parameter.

Try:

[[tView text] dataUsingEncoding:NSUTF8StringEncoding]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM