Convert bytes to megabytesTag(s): String/Number


import java .io.*;

public class Test {

 public static void main(String args[]) {
   // a big file ...
   File f = new File("news.easynews.com.newsrc");
   System.out.println(f.length());
   System.out.println(bytesToMeg(f.length()) + " Mb");
 }

 private static final long  MEGABYTE = 1024L * 1024L;

 public static long bytesToMeg(long bytes) {
  return bytes / MEGABYTE ;
 }
}

blog comments powered by Disqus