I am developing an Android application in Ionic where I put a pre-populated database in apk. User can insert and delete records and initially the size of DB file is 217kb . I want to track after some time what is the current DB file size on user's device.
我正在开发一个Ionic的Android应用程序,我将一个预填充的数据库放在apk中。用户可以插入和删除记录,最初DB文件的大小是217kb。我想在一段时间后跟踪用户设备上当前的DB文件大小。
Thanks in Advance!
提前谢谢!
2 个解决方案
#1
2
Can use :
可以使用:
// "/data/data/YOUR_PACKAGE/databases/";
// OR
String path=context.getDatabasePath(DataBaseHelper.dbName).toString;
File file = new File(path);
long length = file.length(); // File size
#2
0
you may get it using this:
你可以用这个:
// Get file from file name
File file = new File("path to your file");
// Get length of file in bytes
long fileSizeInBytes = file.length();
// Convert the bytes to Kilobytes (1 KB = 1024 Bytes)
long fileSizeInKB = fileSizeInBytes / 1024;
// Convert the KB to MegaBytes (1 MB = 1024 KBytes)
long fileSizeInMB = fileSizeInKB / 1024;
#1
2
Can use :
可以使用:
// "/data/data/YOUR_PACKAGE/databases/";
// OR
String path=context.getDatabasePath(DataBaseHelper.dbName).toString;
File file = new File(path);
long length = file.length(); // File size
#2
0
you may get it using this:
你可以用这个:
// Get file from file name
File file = new File("path to your file");
// Get length of file in bytes
long fileSizeInBytes = file.length();
// Convert the bytes to Kilobytes (1 KB = 1024 Bytes)
long fileSizeInKB = fileSizeInBytes / 1024;
// Convert the KB to MegaBytes (1 MB = 1024 KBytes)
long fileSizeInMB = fileSizeInKB / 1024;