开发者

Writing data in file

开发者 https://www.devze.com 2023-01-06 21:06 出处:网络
I do a iphone apps and I try to write in a file like this: data = [NSMutableData dataWithBytes:LogString length:[LogString length]];

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号