Here you can find the source of formatMemorySize(Long afreeDiskSpace)
public static String formatMemorySize(Long afreeDiskSpace)
//package com.java2s; public class Main { private static Long freeDiskSpace; public static String formatMemorySize(Long afreeDiskSpace) { freeDiskSpace = afreeDiskSpace;/* w ww.j ava 2 s .c o m*/ if (afreeDiskSpace < 1024) { return "Free Disk Space: " + afreeDiskSpace + "B"; } else if (afreeDiskSpace < 1048576) { return "Free Disk Space: " + afreeDiskSpace / 1024 + "KB"; } else if (afreeDiskSpace < 1073741824) { return "Free Disk Space: " + afreeDiskSpace / 1048576 + "MB"; } else { return "Free Disk Space: " + afreeDiskSpace / 1073741824 + "GB"; } } }