zoukankan      html  css  js  c++  java
  • OC8_NSData

    //
    //  main.m
    //  OC8_NSData
    //
    //  Created by zhangxueming on 15/6/19.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            NSString *string = @"i love ios";
            //把字符串对象转换成NSData对象
            NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
            NSLog(@"data = %@", data);
            
            //把NSData类对象转换成字符串对象
            NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"str = %@", str);
            
            //把data对象数据写到指定文件中,文件不存在,则创建指定文件
            //- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile;
            BOOL ret = [data writeToFile:@"/Users/zhangxueming/Desktop/Test/data.txt" atomically:YES];
            NSLog(@"ret = %i", ret);
            //把文件内容读成二进制对象
            NSData *data1 = [NSData dataWithContentsOfFile:@"/Users/zhangxueming/Desktop/Test/data.txt"];
            NSLog(@"data1 = %@", data1);
            
        }
        return 0;
    }
  • 相关阅读:
    计算机英语
    NSQ学习记录
    Java学习记录-注解
    VS插件开发

    双链表
    顺序表
    顺序队列
    顺序栈

  • 原文地址:https://www.cnblogs.com/0515offer/p/4589593.html
Copyright © 2011-2022 走看看