Java获取文件大小

一、通过length方法:

1、创建一个文件:

1 File file = new File("E:\\全部软件\\软件压缩包\\Windows7_W64_SP1_ent.iso");

2、获取文件大小:

复制代码

    /**
     * 获取文件长度
     * @param file
     */
    public static void getFileSize1(File file) {
        if (file.exists() && file.isFile()) {
            String fileName = file.getName();
            System.out.println("文件"+fileName+"的大小是:"+file.length());
        }
    }

like12---

//like12 add,20170314,bug,个别学员照片 文件存在 但大小为0

if(!StringUtils.isEmpty(employee.getPhoto())){

//判断文件大小是否为0

String filePath = com.bstek.dorado.core.Configure

.getString(Constants.file_upload_config_path) +

"/" + employee.getPhoto();

File f = new File(filePath);

if (f.exists() && f.isFile()) {

if(f.length() <= 0){

return "照片文件大小为:" + f.length() +

",是无效图片,请重新上传!";

}

} else {

return employee.getPhoto() + "照片文件不存在!";

}

}

猜你喜欢

转载自blog.csdn.net/tanzongbiao/article/details/82528673
今日推荐