使用[NSBundle mainBundle]寫入文件失敗我試圖從一個文件中取出內(nèi)容并將其寫入另一個文件。我讀得很好,但我無法將其寫入另一個文件。我有一個單詞數(shù)據(jù)庫。我想根據(jù)字母數(shù)將單詞分成不同的文件。所有四個字母單詞都放在一個文件中,依此類推。我在我的資源中添加了一個名為“4letter”的txt文件,以下是我的代碼:NSError *error;//READNSString *dbFile = [[NSBundle mainBundle] pathForResource:@"words" ofType:@"txt"];NSString *test = [NSString stringWithContentsOfFile:dbFile encoding:NSUTF8StringEncoding error:&error];//convert from string to arrayNSArray *lines = [test componentsSeparatedByString:@"\n"]; NSFileHandle *logFile = nil;logFile = [NSFileHandle fileHandleForWritingAtPath:[[NSBundle mainBundle] pathForResource:@"4letter" ofType:@"txt"]];//Test if write worksfor (int i=0; i<5; i++) {
NSString *randomAnagram = [[lines objectAtIndex:i] lowercaseString];
[logFile writeData: [randomAnagram dataUsingEncoding: NSNEXTSTEPStringEncoding]];}
使用[NSBundle mainBundle]寫入文件失敗
月關(guān)寶盒
2019-07-31 10:40:54