查询结果 |
|
弹出框页面代码:
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
后台代码
@ManagedBean(name = "patchBean")
@SessionScoped
public class TreeBean{
//导入补丁文件
public void importPatchFile(FileUploadEvent event){
FacesMessage msg = null;
try {
//新建文件输入流并对它进行缓冲
InputStream in = event.getFile().getInputstream();
BufferedInputStream inBuff = new BufferedInputStream(in);
// 新建文件输出流并对它进行缓冲
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.setCharacterEncoding("UTF-8");
File oldFile = new File(CURRENT_FILE_PATH+"\\"+event.getFile().getFileName());
if(!oldFile.exists()){
FileOutputStream output = new FileOutputStream(CURRENT_FILE_PATH+"\\"+event.getFile().getFileName());
BufferedOutputStream outBuff=new BufferedOutputStream(output);
// 缓冲数组
byte[] b = new byte[1024 * 5];
int len;
while ((len =inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
// 刷新此缓冲的输出流
outBuff.flush();
inBuff.close();
outBuff.close();
output.close();
in.close();
files.clear();
this.getSubFiles(CURRENT_FILE_PATH);
msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"操作成功",null);
}else{
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,"该文件已存在",null);
}
FacesContext.getCurrentInstance().addMessage("uploadfile-model-form:messages", msg);
} catch (Exception e) {
System.out.println("上传出异常了");
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,"操作失败",null);
FacesContext.getCurrentInstance().addMessage("uploadfile-model-form:messages", msg);
e.printStackTrace();
}
}
}