NSDate设置的缓冲区对于32位应用程序来说最多可以存储2GB的数据,对于64位的这个自己算吧好多(2的63次幂GB)
代码:
- #import <Foundation/Foundation.h>
- int main()
- {
- @autoreleasepool{
- const char *string = "Hi,lsmseed";
- NSDdata *data = [NSData dataWithBytes:string length:strlen(string)+1];
- NSLog(@"--------%@",data);
- NSLog(@"length = %d, string = %s",[data length],[data bytes]);
- [data writeToFile:@"/Users/lsmseed/Desktop/tt.txt" atomically:TRUE];
- return 0;
- }
- }
复制代码
- #import<Foundation/Foundation.h>
- int main()
- {
- @autoreleasepool{
- NSFileManager *fm;
- NSData *fileData;
- fm = [NSFileManager defaultManager];
- fileData = [fm contentsAtPath:@"/users/lsmseed/desktop/tt.txt"];
- if(fileData == nil)
- {
- NSLog(@"file read failed!");
- return 1;
- }
- if([fm createFileAtPath:@"/user/lsmseed/desktop/nn.txt" contents:fileData attributes:nil] == NO)
- {
- NSLog(@"don't create");
- }
- [NSString stringWithContentsOfFile:@"/user/lsmseed/desktop/nn.txt" encoding:NSUTF8StringEncoding error:nil]);
- }
- return 0;
- }
复制代码
我定义了一段字符串将它存储在NSDdata数据缓冲区中,首先把tt.txt文件中的内容读入缓冲区,再将其中的内容写入nn.txt文件中。 |