我一直在嘗試 Java 的物件 ox io。它在 Android 上運行良好,因此我決定在 Java 桌面實作上使用它。
我面臨的問題是我可以在運行時保存我的資料,但是當我重新啟動應用程式或桌面應用程式時,資料消失了,被遺忘了,這很奇怪。我試圖尋找解釋,但沒有找到任何相關資訊。任何人都可以幫助或知道為什么會這樣嗎?與此同時,我已經恢復使用 SQLite。該應用程式旨在非常大并且有很多多執行緒。
這是一個樣本
import io.objectbox.BoxStore;
import io.objectbox.DebugFlags;
import lombok.SneakyThrows;
import java.io.File;
import java.io.IOException;
public class DBObjectManager {
public static DBObjectManager objectIOAccessInstance ;
private BoxStore store;
private DBObjectManager() {
File tempFile = null;
try {
tempFile = File.createTempFile("objectdb", "");
} catch (IOException e) {
e.printStackTrace();
}
tempFile.delete();
store = MyObjectBox.builder()
.directory(tempFile)
.debugFlags(DebugFlags.LOG_QUERIES | DebugFlags.LOG_QUERY_PARAMETERS)
.build();
}
public static DBObjectManager getinstance() {
if (objectIOAccessInstance == null) {
objectIOAccessInstance = new DBObjectManager();
}
return objectIOAccessInstance;
}
public BoxStore getStore() {
return store;
}
}
uj5u.com熱心網友回復:
每次執行應用程式時,您都會創建一個新的臨時檔案。我想這解釋了你的問題。
從檔案:
creates a new empty file in the specified directory. deleteOnExit() method is called to delete the file created by this method.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/479736.html
