Below sample code can save a string “abcdefghijk” to Application/”1.txt” file
NSString *str2 = @"abcdefghijk";
NSMutableData *dat1 = [[[NSMutableData alloc] autorelease] initWithCapacity:1];
[dat1 appendBytes:[str2 cString] length:[str2 cStringLength]];
[self funFileSave:@"1.txt" i_receivedData:dat1];
- (void)funFileSave:(NSString*)i_FileName
i_receivedData:(NSMutableData*) i_receivedDataData
{
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:i_FileName];
NSLog(filePath);
NSFileManager *myFile = [ NSFileManager defaultManager];
[myFile createFileAtPath:filePath contents:i_receivedDataData attributes:nil];
}
////////////////////////
Below sample code can laod a string from Application/”1.txt” file
NSString* t_FileData=[self funFileLoad:@"1.txt"];
- (NSString* )funFileLoad:(NSString*)i_FileName
{
NSString *outData="";
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:i_FileName];
NSLog(filePath);
NSFileManager *fm = [NSFileManager defaultManager];
BOOL success = [fm fileExistsAtPath:filePath];
if (success==YES)
{
outData = [NSString stringWithContentsOfFile:filePath];
NSLog(outData);
}
return outData;
}