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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With