Programming/iPhone, Xcode
iOS - iPhone 에 있는 파일들의 경로를 읽어 오기
starblood
2013. 1. 23. 21:28
iPhone 에 파일이름은 같은데, 경로가 다른 파일들을 저장할 수 있다.
예를 들면 아래와 같은 경우,
dir1/sea.jpg
dir2/sea.jpg
dir3/dir5/sea.jpg
이럴 경우에 파일의 경로를 얻어오는 방법이 있다.
아래와 같이 파일 이름을 얻어 올때, 디렉토리를 지정하여 얻어오는 방법이 있다.
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *filePath = nil;
if (filePath = [bundle pathForResource:@"sea" ofType:@"jpg" inDirectory:@"dir1"]) {
theContents = [[NSString alloc] initWithContentsOfFile:filePath];
// when completed, it is the developer's responsibility to release theContents
}