记录1

来源:互联网 发布:qq群网络原因下载失败 编辑:程序博客网 时间:2024/05/16 14:40
    public boolean uploadFile() throws IOException {          FileOutputStream fos=null;          FileInputStream fis=null;        try {            fos = new FileOutputStream(this.savePath+this.filePathFileName);           fis =new FileInputStream(this.filePath);            byte[] bytes=new byte[1024];            int real=fis.read(bytes);            while(real>0){                fos.write(bytes,0,real);                real=fis.read(bytes);            }              success=true;          //    this.saveAttachFile();        } catch (FileNotFoundException e) {            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.             getResponse().setContentType("text/html;charset=utf-8");            getResponse().getWriter().print("{success:flase,message:'失败'}");        } catch (IOException e) {            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.             getResponse().setContentType("text/html;charset=utf-8");            getResponse().getWriter().print("{success:flase,message:'失败'}");        }   finally {            //关闭输入流            fis.close();            //关闭输出流            fos.close();        }        System.out.println("上传文件名"+filePathFileName);//        System.out.println("上传文件类型"+myFileContentType);//       success = true;       return   success;    }/** * 上传文件并添加上传记录 * * @return 标示符 * @throws BusinessException *             运行时异常 */public String saveAttachFile() throws IOException{       boolean  stauts=uploadFile();        if(stauts){Map<File, String> hashMap = new HashMap<File, String>();hashMap.put(this.filePath, this.filePathFileName);CommonAttachFile commonAttachFile = new CommonAttachFile();commonAttachFile.setFileId(Long.valueOf(IDUtil.getNextSeqence()));//commonAttachFile.setFileId(IDUtil.getNextLongID());commonAttachFile.setFileName(this.filePathFileName);            try {                fileUploadCommonService.saveAttachFile(commonAttachFile, this, hashMap);                 commonAttachFile = (CommonAttachFile)fileUploadCommonService.findObject(                PTIM_CA_SEARCHATTACHFILE, commonAttachFile.getFileId());// 将已上传文件copy到摆渡用upload文件夹            fileUploadCommonService.copyAttachFile(commonAttachFile);            } catch (BusinessException e) {                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.                getResponse().setContentType("text/html;charset=utf-8");                getResponse().getWriter().print("{error:true,message:'失败'}");                return null;            }            commonAttachFileList = new ArrayList<CommonAttachFile>();            success = true;            commonAttachFileList.add(commonAttachFile);            getResponse().setContentType("text/html;charset=utf-8");            getResponse().getWriter().print("{success:true,fileName:'" + commonAttachFile.getFileName() + "'," +                    "filePath:'" + commonAttachFile.getFilePath().replace("\\", "\\\\") + "',id:'" + commonAttachFile.getFileId() + "'}");      }   else{            getResponse().setContentType("text/html;charset=utf-8");            getResponse().getWriter().print("{success:flase,message:'失败'}");        }return null;}


	
				
		
原创粉丝点击