Here the registration number is given as 100, what I want is;
Instead of determining the number of records from the beginning, I want the number of records to increase as I add records.
I will exemplify what I want to tell through arrays;
Not so;
Array[100];
Array[0]=data;
Like this;
Array[];
Array.push(data);
import com.deitel.jhtp6.ch24.RandomAccessAccountRecord;
import java.io.IOException;
import java.io.RandomAccessFile;
public class CreateRandomFile {
private static final int NUMBER_RECORDS = 100;
public void createFile() {
RandomAccessFile file = null;
try {
file = new RandomAccessFile("clients.dat", "rw");
RandomAccessAccountRecord blankRecord = new RandomAccessAccountRecord();
for (int count = 0; count < NUMBER_RECORDS; count++)
blankRecord.write(file);
System.out.println("Created file clients.dat.");
System.exit(0);
} catch (IOException ioException) {
System.err.println("Error processing file.");
System.exit(1);
} finally {
try {
if (file != null)
file.close();
} catch (IOException ioException) {
System.err.println("Error closing file.");
System.exit(1);
}
}
}
}
It can be done by counting the number of recordings and adding +1 each time, but this is not practical or professional at all.