Friday, September 12, 2014

iOS 파일 읽기 쓰기

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    
    NSFileManager * fileManager = [NSFileManager defaultManager];
    NSString *currentPath = [fileManager currentDirectoryPath];
    
    NSArray *dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [dirPath objectAtIndex:0];

    NSLog(@"currentPath %@", currentPath);
    NSLog(@"documentPath %@", documentPath);
    
    if ([fileManager changeCurrentDirectoryPath:documentPath] == NO){
        // 폴더 이동 못함
    } else {
        // 폴더 이동함
        NSLog(@"폴더 이동");
    }
    
    char *bytes = "1234";
    NSData *data = [[NSData alloc]initWithBytes:bytes length:4];
    [fileManager createFileAtPath:@"test.txt" contents:data attributes:nil]; 
}

No comments:

Post a Comment