다음 코드로 문서 디렉토리에있는 PDF 파일의 파일 크기를 검색하고 있습니다.
- (NSString *)sizeOfFile:(NSString *)filePath {
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSInteger fileSize = [[fileAttributes objectForKey:NSFileSize] integerValue];
NSString *fileSizeString = [NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleFile];
return fileSizeString;
}
NSURL *url = [self.arrayOfBooks objectAtIndex:indexPath.row];
NSLog(@"%@",[self sizeOfFile:url.absoluteString]); // Showing zero KB.
에서 arrayBooks
볼 수 있기 때문에 파일이 있다고 확신합니다 cellForRowAtIndexPath
.
하지만 파일 크기가 0으로 표시되는 이유를 모르겠습니다.
제발 도와주세요.
문제의 가장 가능성있는 원인은 잘못된 경로가로 전송 되었기 때문 sizeOfFile:
입니다.
코드 :
NSURL *url = [self.arrayOfBooks objectAtIndex:indexPath.row];
NSLog(@"%@",[self sizeOfFile:url.absoluteString]); // Showing zero KB.
해야한다:
NSURL *url = [self.arrayOfBooks objectAtIndex:indexPath.row];
NSLog(@"%@",[self sizeOfFile:[url path]]);
path
메서드 를 호출하여 파일 경로를 가져 오려고합니다. absoluteString
경로가 아닌 파일 URL을 반환합니다.
또한 속성 구문을 사용하여 메서드를 호출하지 마십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다