How to convert byte size into human-readable format in Java? Like 1024 should become "1 Kb" and 1024*1024 should become "1 Mb".
I am kind of sick of writing this utility method for each project. Are there any static methods in Apache Commons for this?
Use Android builtin Class
For Android there is a class Formatter. Just one like of code and you are done.
It is Like
formatFileSize()
, but trying to generate shorter numbers (showing fewer decimals).Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.
Maybe you can use this code(in C#):