2012-06-15 2 views
0

NSKeyedArchiver와 NSFileManager를 :내가 디스크에 파일을 저장하려고 다음과 같은 오류가 무엇입니까 문제

여기
ERROR IS Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x8d44150 {NSFilePath=/Users/test/Library/Application Support/iPhone Simulator/5.1/Applications/C283C4FF-645A-4C97-BB87-9591ECC57B0D/Library/Caches/newsfeedCache, NSUnderlyingError=0x8d25870 "The operation couldn’t be completed. Is a directory"} 

NSMutableData *data = [[NSMutableData alloc] init]; 
     NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; 

     NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"test", @"hula", nil]; 

     [archiver encodeObject:dict forKey:kDataKey]; 
     [archiver finishEncoding]; 

     NSLog(@"CACHE PATH IS %@", self.newsfeedCachePath_); 

     NSError *error = nil; 
     BOOL success = [data writeToFile:self.newsfeedCachePath_ options:NSDataWritingAtomic error:&error]; 
     if (success && !error){ 

     } else { 
      FNLog(@"ERROR IS %@", [error description]); 
     } 

     [archiver release]; 
     [data release]; 

어떻게 경로를 생성하고 있어요 :

- (NSString *)createDataPath { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
    NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:cacheName]; 

    /* check for existence of cache directory */ 
    if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { 
     return dataPath; 
    } 

    NSError *error = nil; 
    /* create a new cache directory */ 
    if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath 
            withIntermediateDirectories:NO 
                attributes:nil 
                 error:&error]) { 
     DLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     return nil; 
    }  

    NSString *path = [dataPath stringByAppendingPathComponent:cachePath]; 

    return path; 
} 

내가 잘못하고있는 중이 야 무엇을?

답변

0

파인더를 가지고 Home/Library/Application Support/iPhone Simulator/5.1/Applications/C283C4FF-645A-4C97-BB87-9591ECC57B0D/Library/Caches으로 이동하십시오. newsfeedCache 정말 디렉터리입니까?

EDIT : [data writeToFile :]은 디렉토리 이름이 아닌 파일 이름을 필요로합니다. 디렉토리 이름을 피드하면 오류입니다. 데이터 저장을위한 일종의 계획을 세워야합니다. 응용 프로그램의 세부 사항을 모른 채, 나는 당신을 위해 그것을 생각해 내지 못합니다. 그 캐시 아래에 하나의 파일을 갖고 있습니까? 나중에 어떻게 되 찾을 거니? 기타 등등. 그것들은 수사학적인 질문입니다. 직접 대답하고, 그 대답에 따라 파일 명명 체계를 제안하십시오.

+0

예, 방금 확인한 결과 디렉토리가 잘못 되었습니까? – adit

+0

'[data writeToFile :]'은 디렉토리 이름이 아닌 파일 이름을 요구합니다. 파일은 존재하지 않아도되지만, 존재하고 그것이 디렉토리라면 오류입니다. –

+0

그러면 어떻게 해결할 수 있습니까? 어떻게하면 디렉토리에서 파일 이름을 만들 수 있습니까? 파일 이름으로 현재 경로를 추가해야하지만 파일 이름 확장명은 무엇일까요? – adit

관련 문제