Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create, save, and read text file

I want to open one blank new text file on a button event, edit the text, and save it in a directory, and also read that file at any time.

like image 767
Sam007 Avatar asked May 25 '11 10:05

Sam007


People also ask

How do you create a text file and save it?

Another way to create a text file is to right-click an empty area on the desktop, and in the pop-up menu, select New, and then select Text Document. Creating a text file this way opens your default text editor with a blank text file on your desktop. You can change the name of the file to anything you want.

How do you create a data txt file?

Right-click in the folder and go to New > Text Document. The text file is given a default name, New Text Document. txt, but the file name is highlighted. Type a new name for the file and press Enter.

Is Notepad a text file?

Notepad is an editor that will create text files. It is located in "All Programs", under "Accessories" on a Windows machine. There are other editors that will also work. Be aware of the format of the file you are saving - usually there is a box that gives you a choice.


1 Answers

You can read a text file into a string with this method on NSString:

+ (id)stringWithContentsOfFile:(NSString *)path
                  usedEncoding:(NSStringEncoding *)enc
                         error:(NSError **)error

You can write it again with:

 - (BOOL)writeToFile:(NSString *)path 
          atomically:(BOOL)useAuxiliaryFile 
            encoding:(NSStringEncoding)enc 
               error:(NSError **)error
like image 172
Amy Worrall Avatar answered Sep 28 '22 06:09

Amy Worrall