I have a Java variable from datatype long, containing the size of a file in bytes. I want to display the size of the file in a human-readable way:
- When the size is at least 1GB, show the size in GB, else step 2
- When the size is at least 1MB, show the size in MB, else step 3
- When the size is at least 1KB, show the size in KB
It's possible to program this, but I was wondering if there is already a Java framework present which provides this functionality?
For example I have a variable:
long bytes = 1024L;
I want to print this out as String: "1 KB".