//查找文件路径的函数
NSString *path= [[NSBundle mainBundle]pathForResource:@"student" ofType:@"txt"];
NSError *error=nil;
//stringWithContentsOfFile 是读取 指定路径里的内容 NSUTF8StringEncoding:是对文本编码的
NSString * str1=[NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:&error];
if (error)
{
NSLog(@"oops errpr:%@",[error localizedDescription]);
}
NSLog(@"str1= %@",str1);
*/
//
NSString *str1=@"abc";
//在指定路径创建文件及 并在文件里面写东西
NSString *path2=@"/Users/ibokan/Desktop/k.txt";
NSError *error2=nil;
NSString *str2=[str1 stringByAppendingFormat:@"%@",@"12"];
NSLog(@"%@",str2);
BOOL success= [str2 writeToFile:path2
atomically:YES //YES NO yes的话 先放到缓存里面 no的话 直接往里面放
encoding:NSUTF8StringEncoding
error:&error2];
if (!success)
{
NSLog(@"error2=%@",[error2 localizedFailureReason]);
}
/*
//NSData 二进制 initWithContensOfFile 需要释放
NSData *stuData=[NSData dataWithContentsOfFile:path];
NSString *stuStr=[[NSString alloc]initWithData:stuData
encoding:NSUTF8StringEncoding];
NSLog(@"stustr=%@",stuStr);
//NSFileManger
//创建目录
NSFileManager *manager=[NSFileManager defaultManager];
NSString *path3=@"/Users/ibokan/Desktop/abc";
NSString *path4=@"/Users/ibokan/Desktop/1/1abc.txt";
//创建目录 就是文件夹 withIntermediateDirectories:中间目录 attributes:属性
BOOL succes2= [manager createDirectoryAtPath:path3
withIntermediateDirectories:YES
attributes:nil
error:nil];
NSLog(@"succes2:=%d",succes2);
//创建文件 string 和NSData 能相互互转
NSData *stuFileData=[@"llllxxxxdddd" dataUsingEncoding:NSUTF8StringEncoding];
BOOL s3=[manager createFileAtPath:path4 contents:stuFileData attributes:nil];
NSLog(@"s3=%d",s3);
//删除文件
BOOL s4=[manager removeItemAtPath:path4 error:nil];
NSLog(@"s4=%d",s4);
//移动 mov
//
*/
/*
NSString *path5= [[NSBundle mainBundle]pathForResource:@"baga" ofType:@"plist"];
NSDictionary *dic=[NSDictionary dictionaryWithContentsOfFile:path5];
// NSArray *array=[NSArray arrayWithContentsOfFile:path5];
NSArray *array=[dic allKeys];
NSLog(@"array =%@",array);
NSLog(@"a%@",[dic objectForKey:@"New item"] );
NSLog(@"dic=%@",dic);
//XML