In building a non-trivial application, you need to


In building a non-trivial application, you need to be able to read and write data from a file.
It can be customer information, data about merchandise, or student grades. This is a basic procedure in almost every application.

LiveWire provides a file object which allows your application


LiveWire provides a file object which allows your application to write to the server’s file system.
As a security measure, JavaScript on the browser does not permit saving data to the file system.

Like other JavaScript operations


Like other JavaScript operations, file handling is also done using objects.
LiveWire provides a file object and you create new objects for each file you want to use. If you need to use file files, then create a new file object for each one.

After you create the file object, you then need to open the file


After you create the file object, you then need to open the file before you can do anything else with it.
To open the file, you use the open method, as follows:

result=fileObjectName.open (“mode”)

The result is true if the file was opened successfully; otherwise it is false.

When dealing with data stored in a file


When dealing with data stored in a file, you must consider where in the file the desired data is stored or where you intend to store it. You may not want to read the first three items, but you do want to read the next two items.
The file object allows you to read the current position, change the position, or check if you are at the end of the file.

When you open a file, the current position depends on the mode


When you open a file, the current position depends on the mode you use to open it.
Generally it starts at the beginning of a file, except for modes a+ and a where data is appended at the end of an existing file. For empty or new files, the end of the file and the beginning of the file are the same.

In reading a file you often want to read through the entire thing


In reading a file you often want to read through the entire thing, but to do so you need to know when you have reached the end.
So you test for the end of the file (eof). The file object has the eof method that returns a true after the first read operation that attempts to read past the end of the file.

The file object provides three methods of writing data to a file


The file object provides three methods of writing data to a file. These methods allow you to write a string, write a string followed by a n , or write a single byte to a file.
Each method returns true if successful; otherwise it returns false.The syntax is

fileObj.write(string)
fileObj.writeln(string)
fileObj.writeByte(number)

Like most languages, when data is sent to a file it is stored


Like most languages, when data is sent to a file it is stored in a buffer to increase efficiencies.
This internal buffer stores the data until the buffer is full, until the file is closed, or when flushed.Then it physically writes the data into the file.

Just as there are three methods of writing to a file


Just as there are three methods of writing to a file, so there are three methods to reading a file.
You can read a specific number of bytes, read in the entire next line, or read in a single byte. Each method returns true if successful, otherwise it returns false. The syntax is

fileObj.read(count)
fileObj.readln()
fileObj.readByte()