Files can be read and written by using java script functions – fopen(),fread() and fwrite().
The function fopen() takes two parameters – 1. Path and 2. Mode (0 for reading and 3 for writing). The fopen() function returns -1, if the file is successfully opened.
The function fread() is used for reading the file content.
Ex: str = fread(file,flength(file));
The function fwrite() is used to write the contents to the file.
Ex(): file = fopen(“c:\MyFile.txt”, 3);// opens the file for writing
fwrite(file, str);// str is the content that is to be written into the file.