File Access Types
Jump to navigation
Jump to search
Description
- There are three disk file types that can be accessed by your program. They are: Sequential, Random and Binary.
- A general description of the types:
- Sequential Files - access one record at a time, in order, in the specified mode only (INPUT, OUTPUT, APPEND).
- Random Access Files - access any record, in any order, for any mode (READ or WRITE).
- Binary Access Files - access file data one character at a time, in any order, in any mode (READ or WRITE).
Syntax
- See Sequential Files, Random Access Files, and Binary Files.
Hints
- Sequential files are generally the easiest to use. A limitation of this type is the fact that data MUST be accessed one piece at a time, beginning at the top of the file each time the file is accessed. If your file has 1000 records, and you want the data from record 995, your program will read all the records up to 995 before you can retrieve your data.
- Random files are more versatile in that you can access any information you may want, for either reading or writing, from anywhere in the file. However, to accomplish this function, data must be stored in what are called "fields", which makes this type of data file more complex and, therefore, a bit more difficult to work with.
- Binary files store data in a continuous stream of characters, from beginning to end, with no carriage returns or line breaks, etc. Often, files are opened in binary mode in order to search for and change a specific piece of data.
Below find a table of the relation between file content type and preferred access mode.
Content | Mime Type | Typical Extension | Access Mode | Reading | Writing | Open Mode | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Plain Text | text/plain | ini, txt, log | Sequential | INPUT | read or write | |||||||
Random Access | Random | GET | PUT | read and write (*) | ||||||||
Anything else | bmp, gif, doc, etc. | Binary | INPUT$() | read and write (*) |
(*) The file must be WRITE-able. So attempting to open a read-only file (or file from read-only media, like CD) for RANDOM or BINARY will fail.
Example
' Place a simple, working example of the keyword here
Useful Procedures
' Place a useful function using this keyword here