//返回临时文件路径
-(NSString *) tempPath
{
return NSTemporaryDirectory();
}
//返回documents文件路径
-(NSString *) documentsPath
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [path objectAtIndex:0];
return documentsDir;
}
//读取文件
-(NSString *) readFromFile:(NSString *) filePath
{
//首先判断文件是否存在
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] ) {
NSArray *content = [[NSArray alloc] initWithContentsOfFile:filePath];
NSString *data = [NSString stringWithFormat:@"%@", [content objectAtIndex:0]];
[content release];
return data;
}else{
return nil;
}
}
//写入文件
-(void) writeToFile:(NSString *) text withFileName:(NSString *) filePath
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:text];
[array writeToFile:filePath atomically:YES];
[array release];
}