String fileName=null;
com.sun.webui.jsf.model.UploadedFile uploadedFile = fuAttachment.getUploadedFile();
try {
if (uploadedFile == null) {
}
String uploadedFileName = uploadedFile.getOriginalName();
int index = uploadedFileName.lastIndexOf('/');
if (index >= 0) {
fileName = uploadedFileName.substring(index + 1);
} else {
index = uploadedFileName.lastIndexOf('\\');
if (index >= 0) {
fileName = uploadedFileName.substring(index + 1);
} else {
fileName = uploadedFileName;
}
}
} catch (Exception ex) {
ex.printStackTrace();
//Logger.getLogger(AddIssue.class.getName()).log(Level.SEVERE, null, ex);
}
try {
FacesContext fcontext = FacesContext.getCurrentInstance();
ServletContext scontext = (ServletContext) fcontext.getExternalContext().getContext();
String rootPath = scontext.getRealPath("/");
rootPath = rootPath + "resources\\uploaded";
File dir = new File(rootPath);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir.getCanonicalPath() + File.separatorChar + fileName);
//if (file.length()/1024*1024 <= 1024)
long fileSize = file.length();
uploadedFile.write(file);
}catch(Exception ex){
ex.printStackTrace();
}