1) add more memory to your computer or use a database

2) Read the first record, move the file pointer to the end of the file and read the last record.