// add ---wangzhixin----2009/07/21 start public boolean processFile() { if (checkData()) { try { long time = System.currentTimeMillis(); // BaseConfig tBaseConfig=new BaseConfig(); // ProductCombinationDef // tProductCombinationDef=(ProductCombinationDef)tBaseConfig.getValue("productCombinationDef", "requestScope"); // String fileName =tProductCombinationDef.getRiskCode()+".jpg"; // String fileName = new File(upfile.getName()).getName(); String fileName = new File(upfile.getName()).getName(); String endwith = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); fileName = simpleDateFormat.format(new Date()) + "." + endwith; this.myFile = fileName; System.out.println(fileName); InputStream in = upfile.getInputStream(); if (limitSize(in.available())) { return false; } // (double)((double)in.available()/1024/1024) System.out.println(".............." + in.available()); FacesContext ctx = FacesContext.getCurrentInstance(); HttpSession hs = (HttpSession) ctx.getExternalContext().getSession(true); String directory = hs.getServletContext().getRealPath("/") + "/upload"; directory.replace("\\", "/"); System.out.println("directory....." + directory); directory.replace("\\", "/"); File fileDir = new File(directory); if (!fileDir.exists()) { if (!fileDir.mkdir()) { System.out.println("文件夹创建失败"); } } String file = hs.getServletContext().getRealPath("/") + "/upload/" + fileName; // this.action(fileName, file); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); byte[] buffer = new byte[1024 * 2]; int length; while ((length = in.read(buffer, 0, buffer.length)) > 0) { out.write(buffer, 0, length); } out.flush(); out.close(); copyFileToFront(fileName, file); // 将条款拷贝到前台一份 add by fengzg 2009-06-16 return true; } catch (Exception e) { e.printStackTrace(); return false; } } else { return false; } }