//創建文件 NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSFileManager *fileManager = [NSFileManager def... ...
//創建文件 NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"xxx.txt"]; NSLog(@"-----%@",filePath); if(![fileManager fileExistsAtPath:filePath]) //如果文件xxx不存在 { NSLog(@"xxx.txt is not exist"); if( [fileManager createFileAtPath:filePath contents:nil attributes:nil]) //創建文件 { // } } else { // } //數據寫入文件 NSString *buf=@"數據"; [buf writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil]; //從文件讀數據 NSString * buf = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];