richface:fileupload中实现弹出提示框当上传得Excel文件错误或者数据过大时

2024-12-05 05:01:57
推荐回答(1个)
回答(1):

public class FileUploadBean {
public void uploadListener(UploadEvent event) {
//获取传过来的items,3.2.2之前版本不支持getUploadItems方法
List itemList = event.getUploadItems();
for(int i=0 ; i try {
UploadItem item = (UploadItem) itemList.get(i);
File file = new File("d:\\"+UUID.randomUUID().toString()+".jpg");
//大小不能超过4M
if(item.getFileSize() <= 4000000){
FileInputStream fis = new FileInputStream(item.getFile());
FileOutputStream out = new FileOutputStream(file);
int bytes = 0;
byte[] bteFile = new byte[1024];
while ((bytes = fis.read(bteFile)) != -1) {
out.write(bteFile, 0, bytes);
}
fis.close();
out.close();
}
} catch (Exception e) {

}
}
}
}