0
我想检查我的应用程序缓存的位置始终在增加。 因此,我需要一种方法来随时访问有关当前缓存的信息。 我认为必须有这样一种方法,因为我可以在我的android-smartphone的App-Info中看到缓存的大小。 该应用程序正在后台运行,并且我想在缓存大小升高时进行日志记录。如何获取有关应用程序缓存的代码信息?
我想检查我的应用程序缓存的位置始终在增加。 因此,我需要一种方法来随时访问有关当前缓存的信息。 我认为必须有这样一种方法,因为我可以在我的android-smartphone的App-Info中看到缓存的大小。 该应用程序正在后台运行,并且我想在缓存大小升高时进行日志记录。如何获取有关应用程序缓存的代码信息?
使用下面的代码片段为您的解决方案。
public static byte[] retrieveData(Context context, String name) throws IOException {
File cacheDir = context.getCacheDir();
File file = new File(cacheDir, name);
if (!file.exists()) {
// Data doesn't exist
return null;
}
byte[] data = new byte[(int) file.length()];
FileInputStream is = new FileInputStream(file);
try {
is.read(data);
}
finally {
is.close();
}
return data;
}
下面是完整的的CacheManager类。