2012-02-16 63 views
0

我想在objective-c中使用BIO_new_file(myPath, "r")加載文本文件。 作爲路徑,我從包中獲取當前文檔目錄。Objective-c從包中加載BIO

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *fileName = [NSString stringWithFormat:@"%@/test.txt", documentsDirectory]; 

NSLog(@"%@", fileName); 

const char* cString = [fileName cStringUsingEncoding:NSUTF8StringEncoding]; 

BIO *temp = BIO_new_file(cString, "r"); 
if (!temp) { 
    NSLog(@"Could not load file!"); 
    assert(false); 
} 

但該方法無法加載文件,我收到Could not load file!

這是在Objective-C中使用Openssl的BIO時的一個已知問題嗎?有沒有解決方法?

回答

0

也許在應用程序的文檔目錄中沒有名爲test.txt的文件。嘗試記錄錯誤代碼:

NSLog(@"error code = %s (%d)", strerror(errno), errno); 
+0

謝謝。我非常確定該文件必須在那裏,但它是在捆綁根目錄中,而不是在文檔目錄中。這樣的轉儲故障花了我2個小時......但這是軟件開發...;) – Chris 2012-02-16 11:01:03