FileSize is a small JAVA plugin that provides a fast and easy way to get the size of a file in the format that is needed.
Note if file is not found will return a 0.0 double value.
When sizing up a file you can convert the size to:
- Bytes
- KiloBytes
- MegaBytes
- GigaBytes
- GigaBytes
- TeraBytes
- PetaBytes
- ExaBytes
- ZettaBytes
- YottaBytes
The plugin is available in JitPack. https://jitpack.io/#brajjan79/FileSize
Imports:
import java.io.File;
import com.github.filesize.FileSize;Code:
File someFile = new File("some path to file");
// Non static way
FileSize fileSize = new FileSize(someFile);
double bytes = fileSize.getBytes();
double KiloBytes = fileSize.getKiloBytes();
// This goes on up to YotaBytes
// Static way Deprecated
double bytes = FileSize.size(someFile).getBytes();
double KiloBytes = FileSize.size(someFile).getKiloBytes();
double bytes = FileSize.getBytes(someFile);
double KiloBytes = FileSize.getKiloBytes(someFile);
// This goes on up to YotaBytes