i have one property file which contains some records so i need to delete the records after some time interval let's take 2 minute or 3 minutes, so how can i do that one?
views:
58answers:
1
A:
You should create a timer task to perform your action at a future date. Take a look at the Timer API.
final Properties props = new Properties();
props.setProperty("key", "value");
props.store(outputStream, "Adding key=value");
TimerTask deletePropertyTask = new TimerTask() {
public void run() {
props.remove("key");
props.store(outputStream, "Removing key");
}
};
new Timer().schedule(deletePropertyTask, 3000L); // fire in 3 seconds
I tested a roughly equivalent version of this in the Scala REPL. Here it is:
import java.util._
import java.io._
val props = new Properties
props.setProperty("key", "value")
props.store(System.out, "Message")
val task = new TimerTask() {
def run = {
props.remove("key")
props.storeToXML(System.out, "no comment")
}
}
new Timer().schedule(task, 3000l)
// the properties file is rewritten (to System.out) some 3 seconds later.
Synesso
2010-09-24 06:22:23
@hey thanks Synesso i tested this code thanks for ur help!!!!!!!
vinod
2010-09-24 06:40:26