리소스 폴더 내에있는 Object Bank
디렉터리에있는 파일을 읽으려고합니다. 파일이 존재하지 않는 및 fileExistsAtPath:path
항상 파일이 존재 여부에 관계없이 yes를 반환하는 경우에도리소스 폴더에있는 파일을 읽을 수 없습니다 - iOS
Error Domain=NSCocoaErrorDomain Code=261 "The operation couldn’t be completed. (Cocoa error 261.)" UserInfo=0x8c410d0 {NSFilePath=/Users/ctb/Library/Application Support/iPhone Simulator/6.0/Applications/16881651-3790-4C87-A3A0-1E1D60563684/OAS IPAD.app/Object Bank/70118600.eam, NSStringEncoding=4}
경로는 nil
를 반환하지 않습니다
//Get path for file in object bank
NSString* path = [[NSBundle mainBundle] pathForResource:fileId ofType:@"eam" inDirectory:@"Object Bank"];
NSError *error=nil;
//Check if it is present at the location
Boolean prepositioned=[[NSFileManager defaultManager] fileExistsAtPath:path];
NSLog(@"File Found : %@",[email protected]"Yes":@"No");
//This outputs "File Found : Yes"
//Read file
NSString *fileContents=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
NSLog(@"Prepostioned content length: %d",fileContents.length);
//This outputs "Prepostioned content length: 0"
//if file is present:
if (!error) {
//Do something
}
else
{
//Print the error
NSLog(@"Error : %@",error.description);
}
나는 다음과 같은 오류를 받고 있어요 .
나뿐만 아니라이 시도했습니다
NSArray *paths =[[NSBundle mainBundle] pathsForResourcesOfType:@"eam" inDirectory:@"Object Bank"];
for (NSString *path in paths) {
NSString *fileString=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(@"Resource : %u ",fileString.length);
}
를하지만이 같은 문제가 있습니다.
ducument의 디렉토리에서 읽고 싶습니까? –