Objective C - Create text file to read and write line by line in Cocoa -
i building mac app,i have 2 problem:
- i want create text file read , write data on it. don't know how crate text file read , write data. use struct?
- i want create xml file read , write data on it. can create struct xml?
do have suggestion? in advance
well, create file, use
[[nsfilemanager defaultmanager] createfileatpath:@"your/path" contents:nil attributes:nil]; this creates empty file, can write or read from. write text (or xml), use nsstring's writetofile:atomically:encoding:error: method
nsstring *str = //your text or xml [str writetofile:"your/path" atomically:yes encoding:nsutf8stringencoding error:nil]; to read file, make nsstring contents of file
nsstring *contents = [nsstring stringwithcontentsoffile:@"your/path"]; or, if not contain string, nsdata object file
nsdata *contents = [nsdata datawithcontentsoffile:@"your/path"];
Comments
Post a Comment