HarmonyOS 如何获取Preferences缓存空间大小,以及如何清除Preferences缓存空间?

如题:HarmonyOS 如何获取Preferences缓存空间大小,以及如何清除Preferences缓存空间?

阅读 611
1 个回答

清除Preferences:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-data-preferences-V5\#clear

获取本应用存储的Preferences大小:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-storage-statistics-V5\#storagestatisticsgetcurrentbundlestats9

import { BusinessError } from '@kit.BasicServicesKit';
storageStatistics.getCurrentBundleStats().then((BundleStats: storageStatistics.BundleStats) => {
  console.info("getCurrentBundleStats successfully:" + JSON.stringify(BundleStats));
}).catch((err: BusinessError) => {
  console.error("getCurrentBundleStats failed with error:"+ JSON.stringify(err));
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进