1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| NSError * error = nil; NSArray * fileContentsArray = [fm contentsOfDirectoryAtPath:PATH error:&error]; if (error) { perror("contentsOfDirectoryAtPath"); } NSArray * allFileContentsArray = [fm subpathsOfDirectoryAtPath:PATH error:&error];
[fm createDirectoryAtPath:dstPath withIntermediateDirectories:YES attributes:nil error:&error]; NSString * str = @"今天赵雨铭同学,要给大家讲电子图书类!!!"; NSData * data = [str dataUsingEncoding:NSUTF8StringEncoding]; BOOL ret = [fm createFileAtPath:[PATH stringByAppendingPathComponent:@"1.txt"]contents:data attributes:nil];
[fm removeItemAtPath:PATH error:&error];
[fm copyItemAtPath:[PATH stringByAppendingPathComponent:@"MID/test"]toPath: [PATH stringByAppendingPathComponent:@"test"] error:&error];
[fm moveItemAtPath:[PATH stringByAppendingPathComponent:@"1副本.txt"] toPath: [PATH stringByAppendingPathComponent:@"1.txt"] error:&error];
BOOL ret = [fm fileExistsAtPath:[PATH stringByAppendingPathComponent:@"12.txt"]]; if (ret) { NSLog(@"This file exist!"); } else { NSLog(@"This file No exist!"); } BOOL isDirectory = NO; ret = [fm fileExistsAtPath:[PATH stringByAppendingPathComponent:@"MIDd"] isDirectory:&isDirectory]; if (ret) { if (isDirectory) { NSLog(@"This is a directory!"); } else { NSLog(@"This is normal file!"); } } else { NSLog(@"No such file or directory!"); } NSDictionary * dic = [fm attributesOfItemAtPath:PATH error:&error]; NSLog(@"%@",dic);
【文件句柄类 NSFileHandle】 NSFileHandle * fhForRead = [NSFileHandle fileHandleForReadingAtPath:PATH]; NSFileHandle * fhForWrite = [NSFileHandle fileHandleForWritingAtPath:PATH]; NSFileHandle * fhForUpdating = [NSFileHandle fileHandleForUpdatingAtPath:PATH]; NSData * data = [fhForRead readDataToEndOfFile]; [fhForUpdating readDataOfLength:9];
[fhForWrite writeData:dataForWrite]; [fhForWrite seekToEndOfFile]; [fhForWrite seekToFileOffset:<#(unsigned long long)#>] [fhForUpdating truncateFileAtOffset:10];
[dict1 writeToFile:[PATH stringByAppendingPathComponent:@"dict.plist"] atomically:NO]; [array writeToFile:[PATH stringByAppendingPathComponent:@"array.plist"] atomically:NO];
[file] - > [new] - >[file] - > [OS X] - > [Property List]
NSArray * plistArray = [[NSArray alloc] initWithContentsOfFile:PATH]; NSURL * url = [[NSURL alloc] initWithString:URL]; NSDictionary * dict = [[NSDictionary alloc] initWithContentsOfURL:url];
|