Writing data in file
I do a iphone apps and I try to write in a file like this:
data = [NSMutableData dataWithBytes:LogString length:[LogString length]];
file = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[file seekToEndOf开发者_运维技巧File];
[file writeData: data];
[file closeFile];
But the problem is that if I try to write the string "awf", the content of the file is "†∂…‡
You're not using LogString
correctly. I'm assuming it's a string, since that's the logical choice for an object with a -length
method (and that's not already an NSData
).
If that's the case, you should do:
data = [LogString dataUsingEncoding:NSUTF8StringEncoding];
file = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[file seekToEndOfFile];
[file writeData: data];
[file closeFile];
精彩评论