createFileAtPath:contents:attributes:
内容データで名前と属性を指定してファイルを作ります
-(BOOL)createFileAtPath:(NSString *)path: contents:(NSData *)contents: attributes:(NSDictionary *)attributes:
解説
内容データで名前と属性を指定してファイルを作ります。
返り値
( BOOL )
YES/NO
引数
( NSString * )path
パス
( NSData * )contents
内容
( NSDictionary * )attributes
属性の辞書
フレームワーク
Foundation
クラス
NSFileManager
Instance Methods
使用可能
10.0
参照
- copyPath:toPath:handler:
- linkPath:toPath:handler:
- removeFileAtPath:handler:
- fileManager:shouldProceedAfterError:
- fileManager:willProcessPath:
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { NSString *str = @"~/"; NSFileManager *myFile = [ NSFileManager defaultManager]; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: [NSDate date],NSFileModificationDate, @"owner",@"NSFileOwnerAccountName", @"group",@"NSFileGroupOwnerAccountName", nil,@"NSFilePosixPermissions", [NSNumber numberWithBool:YES],@"NSFileExtensionHidden", nil]; NSString *str2 = @"Mutable data"; NSMutableData *dat1 = [[[NSMutableData alloc] autorelease] initWithCapacity:1]; [dat1 appendBytes:[str2 cString] length:[str2 cStringLength]]; [myFile changeCurrentDirectoryPath:[str stringByExpandingTildeInPath]]; [myFile createFileAtPath:@"createdNewFile" contents:dat1 attributes:dic]; NSLog([myFile currentDirectoryPath]); } @end