package com.hssx.pcbms.util;

public class FileUtil {

	/**
	 * 获取容易识别的文件大小，比如KB, MB, GB
	 * @param size
	 * @return
	 */
	public static String getReadableFileSize(long size) {
		if (size < 1024) {//1K以内
			return size + "byte";
		} else if (size < 1024 * 1024) {//1M以内
			return String.format("%.1fKB", (size*1.0f/1024));
		} else if (size < 1024 * 1024 * 1024) {//1G以内
			return String.format("%.1fMB", (size*1.0f/1024/1024));
		} else {
			return String.format("%.1fGB", (size*1.0f/1024/1024/1024));
		}
	}
	public static void main(String[] args) {
		long l = 1024 * 1024 * 1 * 1024;
		System.out.println(getReadableFileSize(l));
		String substring = "/upload/af9db74095354187b5ee17bce73b6b82.jpg".substring("/upload/".length());
		System.out.println(substring);
	}
}
