NSString* imagePath = [[NSBundle mainBundle]pathForResource:@"menu_default" ofType:@"png"];
NSData* imageData = [NSData dataWithContentsOfFile:imagePath];
NSLog(@"imageData-%@",imageData);
//初始化文件管理器
NSFileManager* fileManager = [NSFileManager defaultManager];
//獲取文件目錄
NSArray* pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* path = [pathArr objectAtIndex:0];
NSString* path1 =[path stringByAppendingPathComponent:@"txt.txt"];
NSString* path2 =[path stringByAppendingPathComponent:@"test.txt"];
[imageData writeToFile:path1 atomically:YES];
//? ? [@"123" writeToFile:path2 atomically:YES encoding:NSUTF8StringEncoding error:nil];//寫入文件
//移動文件---只能把文件移動到一個空的文件里
//? ? if ([fileManager moveItemAtPath:path1 toPath:path2 error:nil]) {
//
//? ? ? ? NSLog(@"移動文件");
//? ? }
//復制文件---只能把文件復制到一個空的文件里
//? ? if ([fileManager copyItemAtPath:path1 toPath:path2 error:nil]) {
//
//? ? ? ? NSLog(@"復制文件");
//? ? }
//刪除文件
//? ? if ([fileManager removeItemAtPath:path2 error:nil]) {
//? ? ? ? NSLog(@"刪除文件");
//? ? }
//寫入文件
[fileManager createFileAtPath:path2 contents:[@"123" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
//讀取文件
NSData* data = [fileManager contentsAtPath:path2];
NSString* str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"str----%@",str);
//? ? if ([fileManager isReadableFileAtPath:path2]) {
//
//? ? ? ? NSLog(@"是否可讀");
//? ? }
//
//
//? ? if ([fileManager isWritableFileAtPath:path1]) {
//? ? ? ? NSLog(@"是否可寫");
//
//? ? }
//? ? if ([fileManager isExecutableFileAtPath:path1]) {
//? ? ? ? NSLog(@"是否可執行");
//? ? }
//? ? //比較兩個文件的內容
//? ? if ([fileManager contentsEqualAtPath:path1 andPath:path2]) {
//? ? ? ? NSLog(@"成功");
//? ? }else{
//? ? ? ? NSLog(@"失敗");
//
//? ? }
//檢查文件是否存在
//? ? if ([fileManager fileExistsAtPath:path]) {
//
//? ? ? ? UIAlertController* alertC = [UIAlertController alertControllerWithTitle:@"系統公告" message:@"目錄存在" preferredStyle:UIAlertControllerStyleAlert];
//? ? ? ? UIAlertAction* alertAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//
//? ? ? ? }];
//? ? ? ? [alertC addAction:alertAction];
//
//? ? ? ? AppDelegate* delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//? ? ? ? [delegate.window.rootViewController presentViewController:alertC animated:YES completion:nil];
//? ? }