My application sends a packet every 30 minutes. When the packet can’t be sent, I want to store it (a simple string) inside a file called error.log. When the user presses a button called “restoreErrors”, I want to extract a packet from error.log and try to resend it, according to the LIFO policy.
For example the file error.log is:
String1
String2
String3
And when the user presses the “restoreErrors” button, I need to load the saved packets in order:
while (!file.empty) {
String str = loadUnsendedStringFromFile();
}
My problem is using the file like a LIFO, because I can read the String correctly, but I need to remove the currently extracted string (like POP in a stack model).
Thanks.
EDIT: Ok, I will use a simple list for achieve this, no need to store inside a file for every packet error… thanks
With an ArrayList, you can call the add method to add unsent messages to your list. Then you can send them in the order you want (going up or down, with a simple for loop). Then, call the remove method to erase the sent string, it will leave you with the unsent Strings