- 追加された行はこの色です。
- 削除された行はこの色です。
&tag(Objective-C/ファイル);
&tag(Objective-C,ファイル);
*目次 [#ya5d2a45]
#contents
*参考情報 [#w4ea8173]
*パスを取得する [#g988b8d9]
** Documentsフォルダのパスを取得しファイル名と結合してフルパスとする。 [#t4610f48]
** Documentsフォルダのパスを取得しファイル名と結合してフルパスとする [#t4610f48]
#pre{{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
}}
** リソースバンドル内のパスを取得しファイル名と結合してフルパスとする [#hf85d8b8]
#pre{{
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [resourcePath stringByAppendingPathComponent:filename];
}}
*ファイルを読み込む [#i5f69a79]
**stringWithContentsOfFile:encoding:errorを使う [#s29c4ba0]
#pre{{
NSError *error = nil;
[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
}}