Programming/iPhone

파일 입출력

통통만두 2010. 6. 30. 15:42
반응형
리소스를 이용한 파일 입출력은 read는 되나 write가 되지 않습니다.
파일을 쓰려면 각 어플마다 존재하는 Document 디렉토리를 이용하여 관리를 해야합니다.
어플을 설치하게 되면 시뮬레이터나 디바이스에 어플의 고유번호 폴더가 생기게 되는데
그 곳의 Document 폴더는 개발자가 직접 관리를 할 수 있습니다.
시뮬레이터에서의 path는
사용자이름/Library/Application Support/iPhone Simulator/User/Applications/어플고유번호/Documents에서
확인을 할 수 있습니다.
대충 소스를 적어 보자면

NSArray* paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullFileName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"test.txt" ];

const char* szFilePath = [fullFileName UTF8String];
FILE* fp = fopen( szFilePath, "w" );
반응형