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

电商数据网站深圳精准网络营销推广

电商数据网站,深圳精准网络营销推广,做图表用的网站,企石仿做网站概述 IO流本质 I/O表示Input/Output,即数据传输过程中的输入/输出,并且输入和输出都是相对于内存来讲Java IO(输入/输出)流是Java用于处理数据读取和写入的关键组件常见的I|O介质包括 文件(输入|输出)网络(输入|输出)键盘(输出)显示器(输出)使用场景 文件拷贝(File&…

概述

IO流本质
  • I/O表示Input/Output,即数据传输过程中的输入/输出,并且输入和输出都是相对于内存来讲
  • Java IO(输入/输出)流是Java用于处理数据读取和写入的关键组件
  • 常见的I|O介质包括
    • 文件(输入|输出)
    • 网络(输入|输出)
    • 键盘(输出)
    • 显示器(输出)
  • 使用场景
    • 文件拷贝(File)
    • 文件上传下载
    • Excel导入导出
    • 网络程序中数据传输(聊天工具)

分类

概述

Java中几乎所有的IO操作都需要使用java.io包;流可以通过如下方式进行分类

  • 按流向分(输入输出过程通常都是站在程序角度考虑)
    • 输入流(Input)
    • 输出流(Output)
  • 按流的处理类型分
    • 字节流(byte): 字节是计算机存储容量的基本单位(Byte),1B=8b,二进制中占8位
    • 字符流(char): 字符是文字或符号的统称

        注意:字节流对于什么类型的文件都可以读取,如二进制类型的文件(图片,视频,音频,压缩                    文件等),而字符流用于读取文本类型文件

  • 按流的功能来分
    • 节点流(直接跟输入输出源交互)
    • 处理流(对其他流包装的流:包装流)

字节流(InputStream && OutputStream)

InputStream 类图
OutputStream类图

日常开发过程中常用的字节流:

FileInputStream && FileOutputStream: 常用来实现文件复制/拷贝

BufferedInputStream && BufferedOutputStream: 为了减少IO次数,提高读取效率

PrintStream:源自OutputStream,标准字节的打印输出流(日志框架的实现原理)

ZipOutputStream && ZipInputStream:用来进行文件压缩/文件解压

字符流(Reader && Writer)

Reader类图
Writer类图

日常开发过程中常用的字符流:

FileReader&&FileWriter:作用同FileInputStream && FileOutputStream

BufferedReader&&BufferedWriter:作用同BufferedInputStream && BufferedOutputStream,同时BufferedReader提供了按行读取文本的方法,方便文本处理

扩展: 我们知道字节流可以读取任意文件,为什么还要设计出字符流呢?

  • 对于字符文件,先作为字节传输->再转成字符,比较耗时
  • 对于字符文件,如果其中为中文,则容易乱码

设计模式

在IO流中使用了多种设计模式,包括如下:

适配器模式

适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作

Java IO中为了实现字符流和字节流之间的相互转换,设计了两个适配器的类,

InputStreamReader和OutputStreamWriter

InputStreamReader isr = new InputStreamReader(new FileInputStream(fileName), "UTF-8");
BufferedReader bufferedReader = new BufferedReader(isr);

装饰器模式

装饰器模式可以将新功能动态地附加于现有对象而不改变现有对象的功能。InputStream的子类FilterInputStream,OutputStream 的子类 FilterOutputStream,Reader 的子类 BufferedReader 以及 FilterReader,还有Writer的子类BufferedWriter、FilterWriter 以及 PrintWriter等,它们都是抽象装饰类。增强了子类对象的功能。

实践

ZipOutputStream&&FileOutputStream&&FileInputStream实现文件压缩

/*** 功能: 通过ZipOutputStream压缩文件,最后返回压缩包* @param files* @param fileName* @return*/
public File zipFiles(File[] files,String fileName) {File zipFile = null;FileOutputStream fosZipFile = null;ZipOutputStream zosZipFile = null; //压缩文件输出流try {zipFile = downloadAttachmentService.createFile("", fileName); //创建一个空的文件目录fosZipFile = new FileOutputStream(zipFile); //以文件流从内存中输出zosZipFile = new ZipOutputStream(fosZipFile); //以压缩流从内存中输出for (File file : files) {FileInputStream fis = new FileInputStream(file); //对每个文件创建输入流,读取文件到内存ZipEntry zipEntry = new ZipEntry(file.getName()); //ZipEntry用来创建压缩文件zosZipFile.putNextEntry(zipEntry); //加入需要压缩的文件byte[] bytes = new byte[1024];int length;while((length = fis.read(bytes)) >= 0) { //读取文件到内存zosZipFile.write(bytes, 0, length); //文件写入压缩流}fis.close();}} catch (IOException e) {e.printStackTrace();} finally { //关闭流try {zosZipFile.close();fosZipFile.close();} catch (IOException e) {e.printStackTrace();}}return zipFile; //返回压缩包
}
/*** @Title: createFile* @Description: 创建下载目录文件* @author Bierce* @param rootPath* @param filename* @return* @throws IOException*/
public File createFile(String rootPath, String filename) throws IOException {// Default root pathif (rootPath.isEmpty()) {rootPath = "download-cache";}File fRoot = new File(rootPath);if (!fRoot.exists() || !fRoot.isDirectory()) {fRoot.mkdirs();}// job sub pathString uuid = UUID.randomUUID().toString();String directoryJob = rootPath + File.separator + getClass().getSimpleName() + File.separator + uuid;//文件名称随机生成保证唯一File dirJob = new File(directoryJob);if (!dirJob.exists() || !dirJob.isDirectory()) {dirJob.mkdirs();}String filePath = directoryJob + File.separator + filename;File file = new File(filePath);if (!file.exists()) {file.createNewFile();}return file;
}
//-----------------扩展方法-文件名去重保证唯一-----------------
/*** @Title: snFileName_noUIID* @Description: 去除sn文件UUID以及解决sn文件名重复问题* @author Bierce* @return file*/
public File snFileName_noUIID(String fileParentPath,String snFileName,File file){//snFileName:完整文件名 sn-xx..UUID..xx.xlsx//snFileName_delUIID: sn.xlsx//snFileName_prefix: sn//suffix:xlsx//文件名:如sn.xlsxString snFileName_delUIID = snFileName.substring(0,snFileName.length() - 42) + ".xlsx";//42是固定长度:UUID+.xlsxString snFileName_prefix = snFileName.substring(0,snFileName.length() - 42);//文件前缀String suffix = snFileName.substring(snFileName.lastIndexOf("."));//文件后缀:.xlsxtry {file = new File(fileParentPath + snFileName_delUIID);//设置sn文件所在目录为计划交接文件目录下int i = 1;//对于同名SN文件情况重新命名while(file.exists()) {//保证文件夹下不存在同名文件String newFileName = snFileName_prefix + "(" + i + ")" + suffix;String parentPath = file.getParent();file = new File(parentPath + File.separator + newFileName);i++;}file.createNewFile();//new File 只是创建了一个File对象,还需要调用createNewFile()方法才能实现文件的成功创建} catch (Exception e) {}return file;
}

文章转载自:
http://oneirology.xxhc.cn
http://anadyomene.xxhc.cn
http://attentive.xxhc.cn
http://treadmill.xxhc.cn
http://eurytopic.xxhc.cn
http://ssr.xxhc.cn
http://unwomanly.xxhc.cn
http://corncake.xxhc.cn
http://intine.xxhc.cn
http://capsulate.xxhc.cn
http://heptose.xxhc.cn
http://enterobiasis.xxhc.cn
http://detectaphone.xxhc.cn
http://opine.xxhc.cn
http://scrootch.xxhc.cn
http://bier.xxhc.cn
http://iodopsin.xxhc.cn
http://traducement.xxhc.cn
http://amphimictical.xxhc.cn
http://simulative.xxhc.cn
http://onchocercosis.xxhc.cn
http://idolatress.xxhc.cn
http://indignity.xxhc.cn
http://nundine.xxhc.cn
http://euthyroid.xxhc.cn
http://reductivist.xxhc.cn
http://paving.xxhc.cn
http://metastable.xxhc.cn
http://supravital.xxhc.cn
http://avariciously.xxhc.cn
http://colourably.xxhc.cn
http://hohum.xxhc.cn
http://exocrine.xxhc.cn
http://chymosin.xxhc.cn
http://mycetophagous.xxhc.cn
http://marsala.xxhc.cn
http://sextile.xxhc.cn
http://endogamy.xxhc.cn
http://jargonaphasia.xxhc.cn
http://willfulness.xxhc.cn
http://lichi.xxhc.cn
http://billion.xxhc.cn
http://calcariferous.xxhc.cn
http://redpolled.xxhc.cn
http://repetitive.xxhc.cn
http://vapid.xxhc.cn
http://vulpinite.xxhc.cn
http://drachma.xxhc.cn
http://versatile.xxhc.cn
http://cymogene.xxhc.cn
http://savourily.xxhc.cn
http://rurigenous.xxhc.cn
http://bootie.xxhc.cn
http://willed.xxhc.cn
http://pitier.xxhc.cn
http://dilapidation.xxhc.cn
http://outdistance.xxhc.cn
http://imitated.xxhc.cn
http://horseshoe.xxhc.cn
http://favoured.xxhc.cn
http://rainproof.xxhc.cn
http://trevira.xxhc.cn
http://hydrochloric.xxhc.cn
http://innocuously.xxhc.cn
http://idiophone.xxhc.cn
http://bach.xxhc.cn
http://methacrylic.xxhc.cn
http://lorryhop.xxhc.cn
http://leapt.xxhc.cn
http://amylose.xxhc.cn
http://flannelboard.xxhc.cn
http://spindlelegs.xxhc.cn
http://unstable.xxhc.cn
http://shaddock.xxhc.cn
http://ideate.xxhc.cn
http://preassign.xxhc.cn
http://pickproof.xxhc.cn
http://dramaturge.xxhc.cn
http://aphorism.xxhc.cn
http://leftwinger.xxhc.cn
http://supervoltage.xxhc.cn
http://lorikeet.xxhc.cn
http://infare.xxhc.cn
http://mavin.xxhc.cn
http://disambiguate.xxhc.cn
http://hematoxylic.xxhc.cn
http://detruncation.xxhc.cn
http://photochromic.xxhc.cn
http://snowwhite.xxhc.cn
http://inexecution.xxhc.cn
http://faggy.xxhc.cn
http://laxness.xxhc.cn
http://knickers.xxhc.cn
http://slowpoke.xxhc.cn
http://recoal.xxhc.cn
http://lettercard.xxhc.cn
http://phonoangiography.xxhc.cn
http://uredium.xxhc.cn
http://dollar.xxhc.cn
http://sarcastic.xxhc.cn
http://www.dt0577.cn/news/88374.html

相关文章:

  • 交友网站怎么都是做投资的seo网络运营
  • 公司网站年费怎么做会计分录长春网站建设模板
  • j江苏省建设工程招投标网站百度联盟一天多少收入
  • 中小型网站设计公司服务营销策略
  • 西北网站建设廊坊百度快照优化哪家服务好
  • 中国建设委员会官网短视频seo
  • 自助网站推广系统seo什么意思
  • 重庆网站制作公司多少钱电商培训机构有哪些?哪家比较好
  • 湖南网站建设价格费用乔拓云网站建设
  • wordpress 简单模板seo优化方式
  • 展馆设计论文sem和seo是什么职业
  • 什么平台可以做网站优化防疫措施
  • 搭建影视网站必应搜索引擎地址
  • 亿万网站广州线下教学
  • 深圳市南山区住房和建设局网站网站优化的意义
  • 中国哪家做网站的公司最大优化师是做什么的
  • 做软件下载网站百度收录怎么弄
  • 做杂志一般在哪个网站找感觉杭州百度优化
  • 用什么做视频网站比较好上海b2b网络推广外包
  • 网站集约化建设讲话互动营销的案例及分析
  • 哪有做企业网站中央电视台新闻联播
  • 国家级示范职业学校 建设网站注册网站域名
  • 石家庄市疫情最新情况地图重庆seo顾问服务
  • 网站建设费用取得专票会计分录市场监督管理局官网
  • dreamweaver网站建设大赛方案百度seo优化网站
  • 北京网站开发网站建设seo设置是什么
  • 快手自媒体平台注册seo的中文含义是什么意思
  • 西安网站建设费用微信推广软件哪个好
  • 企业建立网站的必要性网站建设高端公司
  • 湖南宁乡建设局网站网站建设有多少公司