肥皂起泡泡
方法:通过NSHomeDirectory获得文件路径代码如下:NSString *homeDirectory = NSHomeDirectory();NSString *fileDirectory = [homeDirectory stringByAppendingPathComponent:@"temp/app_data.plist"];1.//使用NSSearchPathForDirectoriesInDomains检索指定路径NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentsDirectory = [paths objectAtIndex:0];zNSString *fileDirectory = [documentsDirectory stringByAppendingPathComponent:@"file.txt"];2.//使用Foundation中的NSTemporaryDirectory函数直接返回代表temp文件夹的全路径的字符串对象NSString *tempDirectory = NSTemporaryDirectory();NSString *file = [tempDirectory stringByAppendingPathComponent:@"file.txt"];实现例子如下:NSArray *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);NSString *docDir = [path objectAtIndex:0];NSLog(@"filepath:%@",docDir);NSString *str = @"hello.jpg";NSString *filepath = [docDir stringByAppendingPathComponent:str];//NSString *filepath = [docDir stringByAppendingPathComponent:[NSString stringWithUTF8String:"///mest.txt"]];NSLog(@"filepath:%@",filepath);BOOL success = [[NSFileManager defaultManager]createFileAtPath: filepath contents:nil attributes:nil];NSLog(@"result",success);printf("Create File:%s %s.",[filepath UTF8String], success ? "Success" : "Error");NSString* reValue= [NSString stringWithString:@"\\"success\\""];