我有一个 android.net.Uri 指向我需要确定文件大小的文件。目前这是使用 contentResolver 上的查询完成的(我使用的是 Xamarin,所以它是 C#):
var cursor = contentResolver.Query(uri, new string[] {
Android.Provider.OpenableColumns.Size,
Android.Provider.OpenableColumns.DisplayName
}, null, null, null);
cursor.MoveToFirst();
size = cursor.GetLong(0);
fileName = cursor.GetString(1);
cursor.Close();
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下都有效,但对于某些文件,该值似乎比正确的文件大小略大(我使用 Total Commander 作为参考)。

必须有更好的方法来做到这一点,我真的需要确切的大小信息,并且由于文件非常大,无法先将它们读入内存。为什么我的方法会产生错误的结果?
在此先感谢您的帮助。