【问题标题】:How to delete the file that is created in the Document directory [duplicate]如何删除在文档目录中创建的文件[重复]
【发布时间】:2014-11-16 23:35:06
【问题描述】:

我使用以下代码创建了一个数据库文件

// Get the documents directory
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = dirPaths[0];

// Build the path to the database file


databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"MyDB.db"]];

如何删除文件“MyDB.db”?

提前致谢。

【问题讨论】:

  • 在发布问题之前请先搜索一下。

标签: ios objective-c nsdocumentdirectory


【解决方案1】:

您可以使用以下内容删除文件

NSError *error;
if(![[NSFileManager defaultManager] removeItemAtPath:databasePath error:&error]) {
    NSLog(@"error while removing file: %@", error.localizedDescription);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多