记录1

    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;
	}




                
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值