How to read/write from textfile + iPhone

-(void) writeToRemember{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *fileName1 = [NSString stringWithFormat:@”%@/Count.txt”, documentsDirectory];
if (FlagRem==TRUE) {
contentCountMin =[NSString stringWithFormat:@”%@,%@”, txtUserName.text, txtPassword.text];
}
else {
NSString *u = @””;
NSString *p = @””;
contentCountMin =[NSString stringWithFormat:@”%@,%@”, u,p];
}

[contentCountMin writeToFile:fileName1 atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];

}

-(void)readFromRemember
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *fileName1 = [NSString stringWithFormat:@”%@/Count.txt”, documentsDirectory];
content = [[NSString alloc] initWithContentsOfFile:fileName1 usedEncoding:nil error:nil];
myCounters = [content componentsSeparatedByString:@”,”];
NSLog(@”%@”,[myCounters description]);
if ([myCounters count]==0) {
txtUserName.text = @””;
txtPassword.text = @””;
FlagRem=FALSE;
[btnRememberMe setSelected:NO];
}
else {
txtUserName.text = [NSString stringWithFormat:@”%@”,[myCounters objectAtIndex:0]];
txtPassword.text = [NSString stringWithFormat:@”%@”,[myCounters objectAtIndex:1]];
[btnRememberMe setSelected:YES];
FlagRem=TRUE;
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s