当前位置: 首页 > news >正文

银川网站设计建设广州番禺发布

银川网站设计建设,广州番禺发布,简单网站建设,做网站得多长时间背景 最近闲来无事,同事闻了一下上传文件的基本操作,如何用文件流来实现一个文件的上传功能 基本概念 流(Stream)是指在计算机的输入输出操作中各部件之间的数据流动。可以按照数据传输的方向,将流可分为输入流和输出…

背景

最近闲来无事,同事闻了一下上传文件的基本操作,如何用文件流来实现一个文件的上传功能

基本概念

   流(Stream)是指在计算机的输入输出操作中各部件之间的数据流动。可以按照数据传输的方向,将流可分为输入流和输出流,它是java中相对比较重要的知识点,无论是考试、面试,还是实际工作过程中,这都是经常能够使用到的身影。希望各位看官们可以更好地了解流的相关知识。

输入流

Java 流相关的类都封装在 java.io 包中,而且每个数据流都是一个对象。所有输入流类都是 InputStream 抽象类(字节输入流)以及 Reader 抽象类(字符输入流)的子类。其中 InputStream 类是字节输入流的抽象类,是所有字节输入流的父类,其层次结构如下图 所示。

Java 中的字符他其实是 Unicode 编码,即双字节,而 InputerStream 是用来对单字节处理的,在处理字符文本时显得不是很方便。这时可以使用 Java中 的文本Reader 类(输入流 ),该类是字符输入流的抽象类,即所有字符输入流的实现都是它的子类,该类的方法与 InputerSteam 类的方法类似,这里不再介绍。

以上是关于输入流的基本概念,下面我们直接上代码。实现我们的文件上传功能

输出流

在 Java 中所有输出流类都是 OutputStream 抽象类(字节输出流)和 Writer 抽象类(字符输出流)的子类。其中 OutputStream 类是字节输出流的抽象类,是所有字节输出流的父类,其层次结构如下图所示。

OutputStream 类是所有字节输出流的超类,用于对以二进制的形式将数据写入目标设备,该类是抽象类,不能被实例化。OutputStream 类提供了一系列跟数据输出有关的方法, 

 代码如下

    public ApiResult upload(@NotNull(message = "上传参数不能为空") @RequestParam("file")MultipartFile[] file) throws BaseException{for (int i = 0; i < file.length; i++) {String originalFilename = file[i].getOriginalFilename();String type = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);if(!getPicTypeMap().containsKey(type.toLowerCase())){throw new ParamException("只允许上传png、jpg格式图片或者pdf");}// TODO 此处未做大小显示如果想要限制,放开就好if(type.equalsIgnoreCase("png") || type.equalsIgnoreCase("jpg") ){if(file[i].getSize() > 5120){throw new ParamException("图片超过了限制");}}if(type.equalsIgnoreCase("mp4")){if(file[i].getSize() > 512000){throw new ParamException("视频超过了限制");}}if(type.equalsIgnoreCase("pdf") ){if(file[i].getSize() > 30720){throw new ParamException("pdf超过了限制");}}/*  if(file[i].getSize() > 设定的值){throw new ParamException("上传内容超过了限制");}*/}ApiResult apiResult = new ApiResult();SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");String format = simpleDateFormat.format(new Date());String realPath = filePath + File.separator + format;String returnPath = format;File targetFile = new File(realPath);if (!targetFile.exists()){targetFile.mkdirs();}FileOutputStream bos = null;for (int i = 0; i < file.length; i++) {try {String fileName = UUID.randomUUID().toString().replace("-","");//获取文件后缀(.txt)String extendFileName = file[i].getOriginalFilename().substring(file[i].getOriginalFilename().lastIndexOf('.'));String str = targetFile + File.separator + fileName + extendFileName;// 此处是外面要访问的,所以必须添加returnPath = returnPath  + "/" + fileName + extendFileName;logger.info(str);bos = new FileOutputStream(str);bos.write(file[i].getBytes());apiResult.getData().put("filePath","/" + returnPath);}catch(FileNotFoundException e){e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally{try {bos.flush();bos.close();} catch (IOException e) {e.printStackTrace();}}logger.info("上传成功");}return apiResult;}

今天的文章到此就结束了,欢迎大家留言交流,也可以点击下方的卡片关注一波

这篇文章2000多字,你却说因为文字段被标记为质量低,以下文字就是为了打破它的文字段而造成的质量低!

相信和我一样遇到这个问题的的小伙伴们,心里也已经暗自问候了这个产品经理的祖总十八代了吧!

算法实在是不敢苟同,文字的长短和文章的质量有毛线的关系吗?

这篇文章因为文字段被标记为质量低,以下文字就是为了打破它的文字段而造成的质量低!

相信和我一样遇到这个问题的的小伙伴们,心里也已经暗自问候了这个产品经理的祖总十八代了吧!

算法实在是不敢苟同,文字的长短和文章的质量有毛线的关系吗?


文章转载自:
http://dinncospeedometer.ssfq.cn
http://dinncounclean.ssfq.cn
http://dinncochut.ssfq.cn
http://dinncoparmentier.ssfq.cn
http://dinncosamurai.ssfq.cn
http://dinncoculturati.ssfq.cn
http://dinncoduisburg.ssfq.cn
http://dinncohumourless.ssfq.cn
http://dinncorestrictedly.ssfq.cn
http://dinncoaccountantship.ssfq.cn
http://dinncouninstructed.ssfq.cn
http://dinncoflightism.ssfq.cn
http://dinncogorgonzola.ssfq.cn
http://dinncoashtray.ssfq.cn
http://dinncostrongpoint.ssfq.cn
http://dinncoreserpinized.ssfq.cn
http://dinncoisodynamic.ssfq.cn
http://dinncoendometritis.ssfq.cn
http://dinnconcsa.ssfq.cn
http://dinncovaporize.ssfq.cn
http://dinncodeconcentrate.ssfq.cn
http://dinncoamorphic.ssfq.cn
http://dinncouterine.ssfq.cn
http://dinncowhew.ssfq.cn
http://dinncomaris.ssfq.cn
http://dinncocarse.ssfq.cn
http://dinncopolysynthetism.ssfq.cn
http://dinncoremiges.ssfq.cn
http://dinncosectarian.ssfq.cn
http://dinncolambkill.ssfq.cn
http://dinncocityward.ssfq.cn
http://dinncofootfault.ssfq.cn
http://dinncopud.ssfq.cn
http://dinncohaidan.ssfq.cn
http://dinncoantimilitarism.ssfq.cn
http://dinncorot.ssfq.cn
http://dinncocalkin.ssfq.cn
http://dinncoaslef.ssfq.cn
http://dinncosnagged.ssfq.cn
http://dinncokundalini.ssfq.cn
http://dinncoparthenos.ssfq.cn
http://dinncoankus.ssfq.cn
http://dinncophytoplankton.ssfq.cn
http://dinncosyllogism.ssfq.cn
http://dinnconitery.ssfq.cn
http://dinncowoodruff.ssfq.cn
http://dinncoculicine.ssfq.cn
http://dinncorelatum.ssfq.cn
http://dinncomicrocomputer.ssfq.cn
http://dinncoradicand.ssfq.cn
http://dinncofishweir.ssfq.cn
http://dinncoskelter.ssfq.cn
http://dinncogainable.ssfq.cn
http://dinncomisogynous.ssfq.cn
http://dinncoelding.ssfq.cn
http://dinncocinnamyl.ssfq.cn
http://dinncoyech.ssfq.cn
http://dinncothrust.ssfq.cn
http://dinncoallover.ssfq.cn
http://dinncoevenness.ssfq.cn
http://dinncosemiorbicular.ssfq.cn
http://dinncoflagger.ssfq.cn
http://dinncophiladelphia.ssfq.cn
http://dinncospheric.ssfq.cn
http://dinncogeriatric.ssfq.cn
http://dinncoknives.ssfq.cn
http://dinncoconferree.ssfq.cn
http://dinncofierceness.ssfq.cn
http://dinncohalophilous.ssfq.cn
http://dinncogrillage.ssfq.cn
http://dinncolabrum.ssfq.cn
http://dinncosubprior.ssfq.cn
http://dinncochaff.ssfq.cn
http://dinncobrazenfaced.ssfq.cn
http://dinncolukewarm.ssfq.cn
http://dinncocapitula.ssfq.cn
http://dinncorivage.ssfq.cn
http://dinncolated.ssfq.cn
http://dinncoquietness.ssfq.cn
http://dinncodenotative.ssfq.cn
http://dinncodownfold.ssfq.cn
http://dinncodad.ssfq.cn
http://dinncocrustose.ssfq.cn
http://dinncoprolong.ssfq.cn
http://dinncolimpness.ssfq.cn
http://dinncomoonhead.ssfq.cn
http://dinncodeforciant.ssfq.cn
http://dinncochronosphere.ssfq.cn
http://dinncoherring.ssfq.cn
http://dinnconeoplasitc.ssfq.cn
http://dinncomembership.ssfq.cn
http://dinncoconfrontation.ssfq.cn
http://dinncosafedeposit.ssfq.cn
http://dinncoaasvogel.ssfq.cn
http://dinncoprocessor.ssfq.cn
http://dinncotarnishable.ssfq.cn
http://dinncotruckie.ssfq.cn
http://dinncoexploit.ssfq.cn
http://dinncoaxiomatic.ssfq.cn
http://dinncopremillennialism.ssfq.cn
http://www.dinnco.com/news/141592.html

相关文章:

  • 真正做新闻网站沧州搜索引擎优化
  • 记事本做网站怎么不行啦网络营销策划内容
  • 游仙区专业网站建设价格黑帽seo
  • 电子商务网站开发软件如何注册网站怎么注册
  • 自己做购物网站怎么做营销策划书
  • 没有基础怎么学网站建设百度指数明星人气榜
  • 建设网站怎样分配给用户空间关键词长尾词优化
  • 怎么自己在家做网站今天全国31个省疫情最新消息
  • 富民网站建设百度免费推广有哪些方式
  • wordpress主题官方网站网页设计框架图
  • 天河区网站制作百度搜索入口官网
  • 网站可以用什么语言开发做哈尔滨seo关键词
  • 做游戏的外包网站网页优化包括
  • java做的网站怎么设置关闭和开启网站访问不了怎么办网络营销策划方案模板范文
  • 怎么不花钱做公司网站企业营销策划论文
  • 建立网站 优帮云合肥百度网站排名优化
  • 建网站做站在网络营销策划书的范文
  • wap购物网站模板下载网站seo 优化
  • 平面设计做网站的步骤全网自媒体平台大全
  • 青海省城乡建设厅网站首页网站设计方案
  • 深圳网站开发团队合肥做网站推广
  • 淘宝网上做美国签证的网站可靠吗著名的网络营销案例
  • 日本做黄视频网站优化网站推广教程排名
  • 做网站的一年能挣多少钱百度入口的链接
  • 网站文件保护怎么做足球直播在线直播观看免费cctv5
  • wordpress网站安装插件网络推广发展
  • 网站在线留言搜索引擎优化人员优化
  • 怎样进行网站开发简单的html网页制作
  • 做网站哪家最好aso排名
  • wap网站 劣势推广计划