Get file size
File file = new File("c:\\geniusLogo.jpg");
double bytes = file.length();
// length() method returns in bytes, so convert it to other unit
double kilobytes = (bytes / 1024);
double megabytes = (kilobytes / 1024);
double gigabytes = (megabytes / 1024);
double terabytes = (gigabytes / 1024);
double petabytes = (terabytes / 1024);
double exabytes = (petabytes / 1024);
double zettabytes = (exabytes / 1024);
double yottabytes = (zettabytes / 1024);
System.out.println(bytes + " bytes");
System.out.println(kilobytes + " kb");
System.out.println(megabytes + " mb");
System.out.println(gigabytes + " gb");
System.out.println(terabytes + " tb");
System.out.println(petabytes + " petabytes");
System.out.println(exabytes + " exabytes");
System.out.println(zettabytes + " zettabytes");
System.out.println(yottabytes + " yottabytes");
No comments:
Post a Comment
Note: only a member of this blog may post a comment.