//字符串的获取
/*
- (instancetype)initWithContentsOfURL:(NSURL *)url usedEncoding:(NSStringEncoding *)enc error:(NSError **)error;
- (instancetype)initWithContentsOfFile:(NSString *)path usedEncoding:(NSStringEncoding *)enc error:(NSError **)error;
+ (instancetype)stringWithContentsOfURL:(NSURL *)url usedEncoding:(NSStringEncoding *)enc error:(NSError **)error;
+ (instancetype)stringWithContentsOfFile:(NSString *)path usedEncoding:(NSStringEncoding *)enc error:(NSError **)error;
*/
// --------------------------------------------------- -----------------------------
//1.把文件写入file中--常用对象方法
/*
NSString *str = @"习大大万岁";
NSError *error = nil;
NSString *path = @"/Users/mawenxing/Desktop/t.txt";
BOOL isW = [str writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"%@",error);
}else{
NSLog(@"写入成功");
}
*/
//2.把文件写入URl中---常用对象方法
/*
NSString *str = @"习大大万岁";
NSError *error =nil;
NSString *path [email protected]"http:/******";
BOOL isWrite =[str writeToURL:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (isWrite) {
NSLog(@"写入成功");
}else{
NSLog(@"error %@",error);
}
*/
// ---------------------------------------------------
//1.从file中读取文件---常用类方法
/*
NSError *error = nil;
NSString *path = @"/Users/mawenxing/Desktop/t.txt";
//1.对象方法读取
NSString *mstr1 =[[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"error %@",error);
}else{
NSLog(@"mstr1 %@",mstr1);
}
//2.类方法读取(常用)---------------------
NSString *mstr2 =[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"error %@",error);
}else{
NSLog(@"mstr2 %@",mstr2);
}
*/
//2.从URl中读取文件---常用类方法
/*
NSError *error = nil;
NSString *path = @"http:/***************";
//1.对象方法读取
NSString *mstr4 = [[NSString alloc] initWithContentsOfURL:path encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"error %@",error);
}else{
NSLog(@"mstr4 %@",mstr4);
}
//2.类方法获取(常用)----------------------
NSString *mstr3 = [NSString stringWithContentsOfURL:path encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"error %@",error);
}else{
NSLog(@"mstr3 %@",mstr3);
}
*/