{"id":585,"date":"2018-02-23T23:40:12","date_gmt":"2018-02-23T15:40:12","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios%e6%96%87%e4%bb%b6%e5%a4%84%e7%90%86\/"},"modified":"2018-02-23T23:40:12","modified_gmt":"2018-02-23T15:40:12","slug":"ios%e6%96%87%e4%bb%b6%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=585","title":{"rendered":"iOS\u6587\u4ef6\u5904\u7406"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>IOS\u6587\u4ef6\u5904\u7406<\/h1>\n<hr>\n<h3>\u7b80\u4ecb<\/h3>\n<p>\u6587\u4ef6\u5904\u7406\u4e0d\u80fd\u76f4\u89c2\u7684\u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u6765\u89e3\u91ca\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u4e86\u89e3IOS\u7684\u6587\u4ef6\u5904\u7406\u3002<\/p>\n<p>IOS\u4e2d\u5bf9\u6587\u4ef6\u7684\u64cd\u4f5c. \u56e0\u4e3a\u5e94\u7528\u662f\u5728\u6c99\u7bb1\uff08sandbox\uff09\u4e2d\u7684\uff0c\u5728\u6587\u4ef6\u8bfb\u5199\u6743\u9650\u4e0a\u53d7\u5230\u9650\u5236\uff0c\u53ea\u80fd\u5728\u51e0\u4e2a\u76ee\u5f55\u4e0b\u8bfb\u5199\u6587\u4ef6\u3002<\/p>\n<h3>\u6587\u4ef6\u5904\u7406\u4e2d\u4f7f\u7528\u7684\u65b9\u6cd5<\/h3>\n<p>\u4e0b\u9762\u5217\u51fa\u4e86\u7528\u4e8e\u8bbf\u95ee\u548c\u64cd\u4f5c\u6587\u4ef6\u7684\u65b9\u6cd5\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u4f60\u5fc5\u987b\u66ff\u6362FilePath1\u3001FilePath\u548cFilePath\u5b57\u7b26\u4e32\u4e3a\u5b8c\u6574\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u4ee5\u83b7\u5f97\u6240\u9700\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728<\/p>\n<pre>\n   NSFileManager *fileManager = [NSFileManager defaultManager];\n   \/\/Get documents directory\n   NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains\n   (NSDocumentDirectory, NSUserDomainMask, YES);\n   NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];\n   if ([fileManager fileExistsAtPath:@\"\"]==YES) {\n        NSLog(@\"File exists\");\n    }    \n<\/pre>\n<p>\u6bd4\u8f83\u4e24\u4e2a\u6587\u4ef6\u7684\u5185\u5bb9<\/p>\n<pre>\n   if ([fileManager contentsEqualAtPath:@\"FilePath1\" andPath:@\" FilePath2\"]) {\n      NSLog(@\"Same content\");\n   }\n<\/pre>\n<p>\u68c0\u67e5\u662f\u5426\u53ef\u5199\u3001\u53ef\u8bfb\u3001\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n<pre>\n  if ([fileManager isWritableFileAtPath:@\"FilePath\"]) {\n      NSLog(@\"isWritable\");\n   }\n   if ([fileManager isReadableFileAtPath:@\"FilePath\"]) {\n      NSLog(@\"isReadable\");\n   }\n   if ( [fileManager isExecutableFileAtPath:@\"FilePath\"]){\n      NSLog(@\"is Executable\");\n   }\n<\/pre>\n<p>\u79fb\u52a8\u6587\u4ef6<\/p>\n<pre>\n   if([fileManager moveItemAtPath:@\"FilePath1\" \n   toPath:@\"FilePath2\" error:NULL]){\n      NSLog(@\"Moved successfully\");\n   }\n<\/pre>\n<p>\u590d\u5236\u6587\u4ef6<\/p>\n<pre>\n   if ([fileManager copyItemAtPath:@\"FilePath1\" \n   toPath:@\"FilePath2\"  error:NULL]) {\n      NSLog(@\"Copied successfully\");\n   }\n<\/pre>\n<p>\u5220\u9664\u6587\u4ef6<\/p>\n<pre>\n if ([fileManager removeItemAtPath:@\"FilePath\" error:NULL]) {\n      NSLog(@\"Removed successfully\");\n   }\n <\/pre>\n<p>\u8bfb\u53d6\u6587\u4ef6<\/p>\n<pre>\n NSData *data = [fileManager contentsAtPath:@\"Path\"];\n <\/pre>\n<p>\u5199\u5165\u6587\u4ef6<\/p>\n<pre>\n  [fileManager createFileAtPath:@\"\" contents:data attributes:nil];\n<\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">IOS\u6587\u4ef6\u5904\u7406 \u7b80\u4ecb \u6587\u4ef6\u5904\u7406\u4e0d\u80fd\u76f4\u89c2\u7684\u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u6765\u89e3\u91ca\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u5b9e\u4f8b\u6765\u4e86\u89e3IOS&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=585\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=585"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}