美文网首页
Foundation框架--文件读写

Foundation框架--文件读写

作者: 程子勋 | 来源:发表于2018-07-18 17:27 被阅读5次

 //读取文件 文件来源 1.本地文件 2.网络文件

        NSURL*httpUrl = [NSURLURLWithString:str10];//网络路径

        NSURL*fileUrl = [NSURLfileURLWithPath:str10];//本地路径

-----------------------------------------------------------------------------------------------------------------

        //读取网络文件

        NSString *httpStr = [NSString stringWithContentsOfURL:httpUrl encoding:NSUTF8StringEncoding error:nil];

        NSLog(@"httpStr =%@",httpStr);

-----------------------------------------------------------------------------------------------------------------

        //读取本地文件

        NSString *fileStr = [NSString stringWithContentsOfFile:@"/Users/macmini/Desktop/log.txt" encoding:NSUTF8StringEncoding error:nil];

        NSLog(@"fileStr =%@",fileStr);

-----------------------------------------------------------------------------------------------------------------

        //写入文件

        BOOL isOK = [str10 writeToFile:@"/Users/macmini/Desktop/Demo.txt" atomically:YES encoding:NSUTF8StringEncoding error:nil];

        if(isOK) {

            NSLog(@"文件写入成功");

        }else{

            NSLog(@"文件写入失败");

        }

-----------------------------------------------------------------------------------------------------------------

相关文章

网友评论

      本文标题:Foundation框架--文件读写

      本文链接:https://www.haomeiwen.com/subject/nkhapftx.html