Freefile function: automatically obtains an idle file number.
Freefile has optional parameters
Freefile (0) returns 1-255;
Freefile (1) returns 256-511
Open the file in binary mode.
Open pfilename for binary as # filenumber
Open the file randomly.
Open pfilename for random as # filenumber
Open the file in write mode.
Open pfilename for output as # filenumber
Open the file as a read.
Open pfilename for input as # filenumber
Open the file with two file numbers. You can read and write the two file numbers at the same time.
Open pfilename for output as # filenumber1
Open pfilename for input as # filenumber2
Close file
Close # filenumber
Obtain the object length.
Lof (filenumber)
Object read/write pointer to the end
EOF (filenumber)
Obtains the current position of the file read/write pointer.
LOC (filenumber)
Set the file read/write pointer to the position specified by START.
Seek filenumber, start
Note: Code A is less efficient than code B in the following code.
If your program is editing a file, you can:
1. Keep the file open until it is closed upon exit. This method saves memory and is efficient, but may lose data.
2. Read all the file information to the memory, and write all the information when exiting. This method is safe, memory consumption, and efficient.
3. enable one read at a time. This method is safer, saves memory, and has the worst efficiency.
Code
For Index = 0 to 100
Open filename for binary as # FN
Get # FN, index, byte
Close # FN
Next
Code B
Open filename for binary as # FN
For Index = 0 to 100
Get # FN, index, byte
Next
Close # FN