How do I create and write data into text file?

Here is an example code to create a text file an put some contents in it. This program will create a file called write.txt.