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;
}
내가 잘못하고있는 중이 야 무엇을?
예, 방금 확인한 결과 디렉토리가 잘못 되었습니까? – adit
'[data writeToFile :]'은 디렉토리 이름이 아닌 파일 이름을 요구합니다. 파일은 존재하지 않아도되지만, 존재하고 그것이 디렉토리라면 오류입니다. –
그러면 어떻게 해결할 수 있습니까? 어떻게하면 디렉토리에서 파일 이름을 만들 수 있습니까? 파일 이름으로 현재 경로를 추가해야하지만 파일 이름 확장명은 무엇일까요? – adit