文件的创建写入读取 日期控件的使用

      最近小结,供自己和大家学习:

           一. [superdealloc] ; 一定要放到最后,如果放在其他dealloc之前可能造成程序不稳定,莫名其妙的崩溃。这个问题困扰小w   N久,程序检查了n遍就是哪里都没问题 单程序就是崩溃  最后请教高人才发现此问题

           二.创建文件夹,文件  读写文件

                 

//获取document目录

NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *documentsDirectory = [pathsobjectAtIndex:0];

//创建文件夹路径

NSString *folderPath = [documentsDirectorystringByAppendingPathComponent:@"text"];

//创建文件夹管理器

NSFileManager *fileManager = [NSFileManagerdefaultManager];

//判大text文件是否存在

BOOL folderExists = [fileManagerfileExistsAtPath:folderPath];

//如果文件不存在则创建文件夹

if (!folderExists) {

[fileManager createDirectoryAtPath:folderPathwithIntermediateDirectories:YESattributes:nilerror:nil];

}

NSString *filePath = [folderPathstringByAppendingPathComponent:@"text.txt"];

//判断文件是否存在

BOOL fileExists = [fileManagerfileExistsAtPath:filePath];

//如果不存在则创建文件

if (!fileExists) {

[fileManager createFileAtPath:filePathcontents:nilattributes:nil];

}

//写文件

NSString *str = @“sssssssss”;

[str writeToFile:filePathatomically:YES];


//读文件   读文件之前应判断文件路径是否存在

NSString *strfile = [NSStringstringWithContentsOfFile:filePath];



      三。NSDate,NSDateFormatter的使用

//默认日期格式为yyyy-MM-dd

NSDateFormatter *dateFormater;

dateFormater= [[NSDateFormatteralloc] init];

[dateFormater setLocale:[[NSLocalealloc]initWithLocaleIdentifier:@"zh_CN"]];//location设置为中国

[dateFormater setDateFormat:@"yyyy-MM-dd  EEEE  hh:mm:ss"];



//picker的默认时间为当前时间

date=[NSDatedate];

    //显示当前时间

self.timeLabel.text = [NSStringstringWithString:[dateFormater stringFromDate:date]];

[dateFormater release];



     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值