1
我試圖讀取JPG文件,並轉換成字節數組 這是下面的代碼此代碼工作正常的文本文件,但是,圖像文件的文件Objective-C的JPG文件轉換爲字節數組
//啓動代碼的代碼
NSString *stringFromFileAtPath = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
if(stringFromFileAtPath == nil){
NSLog(@"Error reading file at path %@\n%@", path, [error localizedFailureReason]);
}
NSLog(@"Contents:%@", stringFromFileAtPath);
NSData *bytes = [stringFromFileAtPath dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Bytes:%@", bytes);
//端,這是錯誤消息我收到 錯誤消息:文本編碼的Unicode(UTF-8)是不適用的。
讓我知道什麼是我做錯誤或代碼爲JPG文件轉換爲字節數組
我有同樣的問題。但我需要轉換大小爲4.0mb的.db文件。當我使用我們的小代碼文件大小的代碼它工作正常。但是當我嘗試轉換4.1mb文件我的應用程序崩潰。對於我的問題有沒有解決方案?謝謝 – Poorna 2012-08-21 10:39:24