可能重複:
Read Text file Programmatically using Objective-C閱讀從.txt文件 - 目標C
我使用的代碼以下行::
- (void)sync:(NSString *)savedName{
NSLog(@"saved name is this :: %@", savedName);
NSString *savedDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *saveFilePath = [savedDir stringByAppendingPathComponent:savedName];
saveFilePath = [saveFilePath stringByAppendingPathComponent:@"edit.txt"];
NSString *saveString = [NSString stringWithContentsOfFile:saveFilePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"saveString is :: %@ savedName : %@ savefilepath : %@", saveString, savedName, saveFilePath);
}
的內容edit.txt
是:
= WWWW =
[[Category:ssss]]
我想要做的是從文件edit.txt
中讀取並將其內容存儲在一個字符串中。但是,在NSLogging上,我得到null
爲saveString
。
我在gdb
以下輸出::
splitView[838:f803] saveString is :: (null) savedName : xxxx savefilepath : /Users/xxxx/Library/Application Support/iPhone Simulator/5.1/Applications/D4B3A4CF-E7D0-4D25-B3D3A170A329/Documents/xxxx/edit.txt`
有人可以幫助我理清錯誤?我無法弄清楚。感謝致敬。
爲什麼你'savedName'參數空?你應該先檢查一下。 – borrrden
它不爲空..它是'xxxx' – kamalbhai
噢拍我混了up savedName和saveString nevermind – borrrden