0
我想將數據寫入.txt文件而不替換舊內容。我已將文件從NSMainBundle移至文檔目錄。我可以編寫該文件通過使用代碼將數據寫入文件而不刪除iPhone中的舊內容
NSData *data=[NSKeyedArchiver archivedDataWithRootObject:recentMainArray];
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[myHandle seekToEndOfFile];
[myHandle writeData:data];
[myHandle closeFile];
但是,當我嘗試顯示該文件的內容,我沒有任何數據that.File在這條道路also.This存在是下面的代碼我使用顯示內容。
NSFileManager *manager = [NSFileManager defaultManager];
//文件路徑 - >文檔目錄文件路徑被打印爲結果爲這兩個nslogs
if([manager fileExistsAtPath:filePath]) {
NSMutableArray *savedArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
NSMutableArray *storedRecentID = [savedArray objectAtIndex:0];
NSMutableArray *storedRecentName = [savedArray objectAtIndex:1];
NSLog(@"ID:%@",[savedArray objectAtIndex:0]);
NSLog(@"Name:%@",[savedArray objectAtIndex:1]);
}
else {
NSLog(@"file not found, save something to create the file");
}
「空」。
請有人讓我知道這個問題的解決方案.FYI,我使用模擬器來測試,這是否創建一個問題。請給我一個解決方案。我搜索了很多,我無法找到解。
謝謝大家提前