Frage

I've added storage file to my codenameone application. In some event I wanna delete specific storage file and recreate it with some old filtered data and new data. It doesn't work well on deletion.

First I create method for clear storage file in StorageManager class:

public void clearData(String pStorageTable){
    Storage.getInstance().deleteStorageFile(pStorageTable);
}

In other class I use this method like this:

// load all data of specific storage file
// ...

new DBManager().clearData(ThreeTrans.DB_NAME);

// write old data with filtering of specific ID and new data
// ...

here is method of write data:

public void write(ThreeTrans pTT){
    if(store == null) {
        store = Storage.getInstance();
    }

    DB_NAME = "TT";

    if(!store.exists(DB_NAME)) {
        Hashtable depHash = new Hashtable();
        String k = "1" + pTT.getNumber();
        depHash.put(k, pTT.toString());
        store.writeObject(DB_NAME, depHash);
    }
    else {
        Hashtable depHash = (Hashtable)store.readObject(DB_NAME);

        if (!depHash.containsValue(pTT.getNumber())) {
            String k = String.valueOf(getLastKeyNumber());
            depHash.put(k, pTT.toString());
            store.writeObject(DB_NAME, depHash);
        }
    }
}

at first I was using this method for delete storage file:

public void clearData(String pStorageTable){
    if(store == null) {
        store = Storage.getInstance();
    }

    for (String str : store.listEntries()) {
        if(str.toLowerCase().startsWith(pStorageTable)) {
           store.deleteStorageFile(str);
        }
    }
}

and after this problem this method changed to this;

public void clearData(String pStorageTable){
    Storage.getInstance().deleteStorageFile(pStorageTable);
}
War es hilfreich?

Lösung

I'm assuming that you didn't invoke close() on the output stream or the input stream working with the file and there is still a lock on the file. This is usually the case for such issues.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top