import dataStorage from '@ohos.data.storage';
import featureAbility from '@ohos.ability.featureAbility'; // 用于获取文件存储路径
var context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
console.info("======================>getFilesDirPromsie====================>"
let promise = dataStorage.getStorage(filePath + '/mystore');
});
promise.then((storage) => {
let getPromise = storage.put('startup', 'auto'); // 保存数据到缓存的storage实例中
getPromise.then(() => {
console.info("Succeeded in putting the value of startup.");
}).catch((err) => {
console.info("Failed to put the value of startup with err: " + err);
})
}).catch((err) => {
console.info("Failed to get the storage.");
})
promise.then((storage) => {
let getPromise = storage.get('startup', 'default');
getPromise.then((value) => {
console.info("The value of startup is " + value);
}).catch((err) => {
console.info("Failed to get the value of startup with err: " + err);
})
}).catch((err) => {
console.info("Failed to get the storage.")
})
let promise = dataStorage.deleteStorage(path + '/mystore');
promise.then(() => {
console.info("Succeeded in deleting the storage.");
}).catch((err) => {
console.info("Failed to delete the storage with err: " + err);
})