后台验证struts2的上传文件大小
/**
? * 返回值true表示验证文件大小通过<br/>
? * 返回值false表示验证文件大小不通过,或者File为null<br/>
? * maxSize参数值1024(KB)表示1M 2048(KB)值表示2M ......
? * @param f
? * @param maxSize 为null表示用系统默认的上限(在upload.properties中设置)
? * @return
? */
?public static boolean checkMaxSize(File f, Long maxSize) {
??boolean re = false;
??//上限
??int max = Integer.parseInt(UploadPropUtil.getValue("maxKB"));
??if(maxSize != null) {
???max = maxSize.intValue();
??}
??if(f == null) {
???return re;
??}
??
??try {
???FileInputStream fis = new FileInputStream(f);
???//千字节大小
???long fileSize = fis.available()/1024;
???if(fileSize >= max) {
????re = false;
???} else {
????re = true;
???}
??} catch(Exception e) {
???e.printStackTrace();
??}
??return re;
?}
?