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.
After you design a few pages, you will develop your own system for editing and testing. The quality of the tool you use is not important; that the tool works for you is.
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.
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.
LiveWire provides a file object which allows your application to write to the server's file system.
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 before you can do anything else with it.
To open the file, you use the open method, as follows:
The result is true if the file was opened successfully; otherwise it is false.
LiveWire also allows you to check on the error status of a file or clear the error status.
Since error status codes are platform dependent, you must check your operating system documentation for the actual codes. The syntax for these methods is
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
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. 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
The data in any of your files is stored in either ASCII text format or binary. The file object has two methods for converting from one format to the other.
Both methods, which follow, are static, so no object is required. The stringToByte method converts the first character of a string into a number. Characters after the first are ignored. The result is a numeric value to the first character or zero.The byteToString method converts a number into a one-character string. If the argument is not a string, the result is an empty string.