有很多关于如何获得SQLite数据库大小的文章,但是这些文章都没有涉及SQLite.Net的实现,而这些实现没有它们在这些文章中调用的相同方法。我可以使用以下方法来使用SQLite.Net获取Android中的文件大小,或者有更好/更快的方法吗?好像很管用。
SQLiteConnection connection;
...
// connection implemented in constructor
...
public long GetDBSize()
{
return File.ReadAllBytes(connection.DatabasePath).LongCount();
}发布于 2017-07-28 21:09:26
可以使用FileInfo获取文件的大小(Length属性):
var fileSize = new FileInfo(sdcardDBPath).Length;示例:
var sdcardDBPath = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, "debug.db");
var fileInfo = new FileInfo(sdcardDBPath);
Log.Debug(Constants.TAG, fileInfo.Length.ToString());输出:
[SushiHangover] 161792亚行ls -l产出:
adb shell ls -l /mnt/sdcard/Download/debug.db
-rw-rw---- 1 root sdcard_rw 161792 2017-07-28 17:08 /mnt/sdcard/Download/debug.db发布于 2017-08-02 13:19:23
使用SushiHangover的答案,我在Github上创建了一个演示应用程序,它还显示了表中的行数。在这里发现的
https://stackoverflow.com/questions/45382268
复制相似问题