5
UTF8Encoded
파일을 서버에서 다운로드하여 앱의 캐시 폴더에 저장하고 콘텐츠를 NSString* var
에 복사하는 iphone 앱을 개발 중입니다. . 그것은 시뮬레이터 장치에서 작동하지만, 여기에 코드 :iPhone 시뮬레이터의 로컬 파일 읽기가 작동하지 않지만 실제 장치에는 없습니다
NSLog(@"File loaded into path: %@\n", localPath);
NSError* error;
NSString* tmpString = [NSString stringWithContentsOfFile:localPath encoding:NSUTF8StringEncoding error:&error];
NSLog(@"Error: %@", error);
//Prints the length in the console to check if the file has been correctly copied in the string
NSLog(@"tmpString length:%u", [tmpString length]);
시뮬레이터 코드 인쇄의이 부분에
:
File loaded into path: /Users/username/Library/Application Support/iPhone Simulator/5.1/Applications/4FCF8FC6-4F1B-4FE5-92F6-A99EC8888E47/Library/Caches/utf8encodedFile.txt
그러나이 표시는 "stringWithContentsOfFile:
"메소드를 호출 할 때 충돌 오류
, 그것은 인쇄합니다 :
File loaded into path: /var/mobile/Applications/1EE8AEEB-D036-4ADE-AE12-836BA1F16BCB/Library/Caches/utf8encodedFile.txt
2012-06-30 19:19:24.743 appName[685:707]
Error: (null)
2012-06-30 19:19:24.745 appName[685:707] tmpString length:1423
당신이 파일이 존재 확신? –
물론, 터미널에서 Cache 디렉터리로 수동으로 이동하고 NsFileManager 메서드로 프로그래밍 방식으로 이동하여 캐시가 있는지 확인했습니다. 캐시를 지우고 파일을 다시 업로드해도 도움이되지 않았습니다. 장치에서 완벽하게 작동하지만 내 개인 장치로 내 응용 프로그램을 테스트하는 것을 좋아하지 않습니다. – user1493309