java中获取图片文件大小

时间:2015-04-17 11:18:52   收藏:0   阅读:308
    /**
     * 判断图片大小
     * @return
     */
    public static boolean judegImgMaxMin(String path){
    	
		boolean flog = true;

		File file = new File(path);
		DecimalFormat df = new DecimalFormat("#.00");
		String str = df.format(file.length() / 1024.0);
		// 最大图片值为15k
		if (Float.parseFloat(str) > 15) {
			flog = false;
		}

		return flog;
    }

 public static void main(String[] args) {  
        String path = "G:\\1.jpg";  
        judegImgMaxMin(path);
//        File file=new File(path);
//        DecimalFormat df = new DecimalFormat("#.00");  
//        System.out.println(df.format(file.length()/1024.0));  
//        System.err.println(NumberFormat.getNumberInstance().format(number));
        
//        System.out.println(img+"");
//        String add=img.toString().getBytes().toString();
//        byteImage(img, "1");  
    }  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!