- 寫文件
NSString* str=@"12345";
NSError *err=nil;
//path是路徑
[str writeToFile:path atomically:YES encoding:NSUnicodeStringEncoding error: &err];
//可以打印錯誤
NSLog(@"%@",err);
NSArray NSDictionary與其類似 都用writeToFile來寫
- 讀文件
//讀plist 用dictionary讀, path是路徑
NSDictionary* dic=[[NSDictionary alloc] initWithContentsOfFile:path];
- 文件管理 NSFileManager
NSFileManager *fm = [NSFileManager defaultManager];
//創建文件
NSString* path=@"/Users/1.csv";
[fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
//判斷路徑下文件是否存在
if([fm fileExistsAtPath:path] == YES){
NSLog(@"存在");
}
//刪除文件
[fm removeItemAtPath:path error:nil];