我正在使用Xcode开发iOS应用程序。在其中一个接口实现(比如接口A)中,我正在文档目录下创建文件。我能够从接口A访问它。但是,如果我尝试访问我在接口A中创建的文件,则从另一个接口(称为接口B),我找不到文件。我在界面B中用来访问文件内容的方法如下:在iOS中创建文件和目录
- (void)loadData{
if ([[NSFileManager defaultManager] fileExistsAtPath:_appFile]) {
NSLog(@"Directory Exists");
_appFile = [_appFile stringByAppendingPathComponent:@"info.txt"];
if ([[NSFileManager defaultManager] fileExistsAtPath:_appFile]) {
NSLog(@"File Exists");
NSData *data = [[NSData alloc] initWithContentsOfFile:_appFile];
if (data!=nil) {
NSMutableDictionary *dict = (NSMutableDictionary *)
[NSKeyedUnarchiver unarchiveObjectWithData:data];
ToDoItem *item = [dict objectForKey:@"0"];
[_toDoItems addObject:item];
}
else{
NSLog(@"Data is empty");
}
}
else{
NSLog(@"File not exists");
}
}
else{
NSLog(@"Directory not exists");
}
}
我收到上述消息“目录不存在”。这个目录与我从接口A引用的目录相同,但不能从接口B访问。谁能告诉我是什么原因。
在此先感谢
你好我使用写我自定义的对象并读该文件。根据你的建议,我无法每次创建文件,当我调用时,这是我最关心的问题 – Chandan