android - humanReadableByteCountBin 在 2GB 文件大小后重新返回负数
问题描述
我正在迭代一个 for 循环,该循环添加文件的字节大小并使用 humanReadableByteCountBin 函数以可读格式获取总和。
在循环中添加文件的字节大小:
File file = new File(sdFile); int file_size = Integer.parseInt(String.valueOf(file.length())); totalSize = totalSize+file_size;
将字节转换为人类可读
humanReadableByteCountBin(totalSize)
人类可读功能
public static String humanReadableByteCountBin(long bytes) { long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes); if (absB < 1024) { //return bytes + " B"; return bytes + "B"; //no space 1B } long value = absB; CharacterIterator ci = new StringCharacterIterator("KMGTPE"); for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) { value >>= 10; ci.next(); } value *= Long.signum(bytes); return String.format("%.1f %ciB", value / 1024.0, ci.current()); }//This method of getting readable file size is an used by the method above
4.调试输出
...
2119779124
2128881125
2137772858
2146700152
-2140127194
-2131631425
-2122627269
...
- 总大小 =
-776.4MiB
如上所示,字节总和直到它们达到 2GB 然后它们开始返回大小减小的负数(如果读取为正数)。我期望的总大小约为 7GB,我该如何实现呢?
解决方案
推荐阅读
- python - python中循环内循环的最佳解决方案
- db2 - DB2 Warehouse on Cloud 默认 PLSQL 兼容性
- django - 在 Django 2 autocomplete_field 上限制查询集
- python - 如何使用 neo4j python 驱动程序获取列表?
- c# - 如何在 asp.net core 2.1 身份 ui 中进行自定义路由?
- python - PySide,如何设置 QMessageBox 文本格式?
- jenkins - 无法在 Jenkins 主页中看到登录和注册选项
- jquery - 将点击功能绑定到不同的图片
- python-3.x - python中的match-mapping-group模式是否有函数式编程的解决方案?
- laravel - 在 laravel 上发布/补丁更新