文件上传-ios端图片保存到后台(针对小格式图片)

文件上传-ios端图片保存到后台(针对小格式图片)

ID:35220497

大小:19.61 KB

页数:4页

时间:2019-03-22

文件上传-ios端图片保存到后台(针对小格式图片)_第1页
文件上传-ios端图片保存到后台(针对小格式图片)_第2页
文件上传-ios端图片保存到后台(针对小格式图片)_第3页
文件上传-ios端图片保存到后台(针对小格式图片)_第4页
资源描述:

《文件上传-ios端图片保存到后台(针对小格式图片)》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、publicclassFileCommon{/****@paramfile上传的文件*@paramfileName上传的文件名*@paramsavePath需要保持的路径*@return*@throwsFileNotFoundException*/@SuppressWarnings({"deprecation","unused"})publicstaticStringupload(Filefile,StringfileName,StringsavePath)throwsFileNotFoundException{FileInputStreamfis=null;Fil

2、eOutputStreamfos=null;StringsaveRootPath=ServletActionContext.getRequest().getRealPath("/");saveRootPath=saveRootPath+savePath;FilefileParent=newFile(saveRootPath);//创建保存文件的上级文件夹if(!fileParent.exists()){booleanflag=fileParent.mkdirs();if(!flag){}}//Stringex=StringTools.getExtention(fil

3、eName);//Stringdate=TimeTools.getStringByFormat(newDate(),"yyyyMMddHHmmss");//fileName=name+"."+ex;fis=newFileInputStream(file);fos=newFileOutputStream(saveRootPath+fileName);byte[]buffer=newbyte[1024];intlen=0;try{while((len=fis.read(buffer))!=-1){fos.write(buffer,0,len);}}catch(FileN

4、otFoundExceptione){System.out.println("Exception:FileNotFoundException");e.printStackTrace();}catch(IOExceptione){System.out.println("Exception:IOExcption");e.printStackTrace();}finally{try{if(fis!=null){fis.close();}}catch(IOExceptione){System.out.println("FileInputStreamclosefailed")

5、;e.printStackTrace();}if(fos!=null){try{fos.close();}catch(IOExceptione){System.out.println("FileOutputStreamclosefailed");e.printStackTrace();}}}returnsaveRootPath+fileName;}//读取ios端传输过来的附件信息publicstaticStringsendData(StringfileName)throwsException{Stringdata=null;Filefile=newFile(fil

6、eName);if(file.exists()){InputStreamis=newFileInputStream(file);byte[]bytes=newbyte[is.available()];is.read(bytes);BASE64Encoderencoder=newBASE64Encoder();data=encoder.encode(bytes);System.out.println(data);}returndata;}//解析ios端上传的文件,并保存到后台@SuppressWarnings("deprecation")publicstaticSt

7、ringdeal(StringsavePath,StringfileName,Stringdata)throwsIOException{StringsaveRootPath=ServletActionContext.getRequest().getRealPath("/");StringmiddlePath=saveRootPath+savePath;Filefile=newFile(middlePath);if(!file.exists()){booleanflag=file.mkdirs();if(!flag){}}OutputStreamfos=newFi

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。