1 void exportString() 2 { 3 NSString *str = @"Hello, 坑爹"; 4 NSString *path = @"/Users/hellovoidworld/Study/Foundation/NSString/abc.txt"; 5 NSError *error; 6 7 [str writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]; 8 9 if(nil == error) 10 { 11 NSLog(@"Write successfully"); 12 } 13 else 14 { 15 NSLog(@"Write fail: %@", error); 16 } 17 } 18 19 int main(int argc, const char * argv[]) { 20 @autoreleasepool { 21 exportString(); 22 } 23 return 0; 24 }
Q1:不能使用相对路径?
经过试验发现不能