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

安顺公司做网站怎么做

安顺公司做网站,怎么做,广西壮族自治区学生资助管理中心,wordpress 主题 36kr1,I/O流的概念: IO流代表的是一个数据输入的源或者输出的目标地址,可以是硬盘,内存,网络或者什么其他的电子设备,而IO流的类型也很多比如最简单的字节或者字符,或者其他更高级的对象。 不管它有多少特性&am…

1,I/O流的概念:
IO流代表的是一个数据输入的源或者输出的目标地址,可以是硬盘,内存,网络或者什么其他的电子设备,而IO流的类型也很多比如最简单的字节或者字符,或者其他更高级的对象。
不管它有多少特性,本质上 流就是一组字节序列,或者直接可以说01字节序列吧?

2,字节流
首先是一个官网例子:CopyBytes.java。


import java.io.*;public class CopyBytes {public static void main(String[] args) throws IOException {read(); //420856988read2(); //1100868readBuffer(); //5977046readBuffer2(); //964845}public static void read() throws IOException {final long l = System.nanoTime();FileInputStream in = null;FileOutputStream out = null;try {String properties = System.getProperty("java.class.path");in = new FileInputStream(properties+"/xanadu.txt"); //想要在IDEA里面跑起来 就把文件放在resources里面//in = new FileInputStream("xanadu.txt"); //否则把文件放在classpath目录里面,使用java命令启动程序out = new FileOutputStream(properties+"/outagain.txt");//out = new FileOutputStream("outagain.txt");int c;while ((c = in.read()) != -1) { //这里每次读取一个字节out.write(c);}} finally {if (in != null) {in.close();//必须得关闭}if (out != null) {out.close();}}System.out.println(System.nanoTime() - l);}public static void read2() throws IOException {final long l = System.nanoTime();FileInputStream in = null;FileOutputStream out = null;try {String properties = System.getProperty("java.class.path");in = new FileInputStream(properties+"/xanadu.txt"); //想要在IDEA里面跑起来 就把文件放在resources里面//in = new FileInputStream("xanadu.txt"); //否则把文件放在classpath目录里面,使用java命令启动程序out = new FileOutputStream(properties+"/outagain.txt");//out = new FileOutputStream("outagain.txt");int c;byte[] bufferBytes = new byte[8192];while ((c = in.read(bufferBytes)) != -1) { //这里每次读取一个字节out.write(bufferBytes,0,c);}} finally {if (in != null) {in.close();//必须得关闭}if (out != null) {out.close();}}System.out.println(System.nanoTime() - l);}public static void readBuffer() throws IOException {final long l = System.nanoTime();InputStream in = null;OutputStream out = null;try {String properties = System.getProperty("java.class.path");in = new BufferedInputStream(new FileInputStream(properties+"/xanadu.txt")); //想要在IDEA里面跑起来 就把文件放在resources里面out = new BufferedOutputStream(new FileOutputStream(properties+"/outagain.txt"));int c;while ((c = in.read()) != -1) { //这里每次读取一个字节out.write(c);}} finally {if (in != null) {in.close();//必须得关闭}if (out != null) {out.close();}}System.out.println(System.nanoTime() - l);}public static void readBuffer2() throws IOException {final long l = System.nanoTime();InputStream in = null;OutputStream out = null;try {String properties = System.getProperty("java.class.path");in = new BufferedInputStream(new FileInputStream(properties+"/xanadu.txt")); //把数据批量读进内存out = new BufferedOutputStream(new FileOutputStream(properties+"/outagain.txt"));int c;byte[] bufferBytes = new byte[8192];while ((c = in.read(bufferBytes)) != -1) { //这个批量读进bufferBytes数组。out.write(bufferBytes,0,c);}out.flush(); //这里可以手动刷新一下,防止数据丢失。} finally {if (in != null) {in.close();//必须得关闭}if (out != null) {out.close();}}System.out.println(System.nanoTime() - l);}
}


2.1 字节流默认每次输入或者输出一个字节(8-bit),类很多,但是所有的都是InputStream/OutputStream的子类,CopyBytes.java使用了FileInputStream和FileOutputStream,但是其他的类的使用方法差不多,除了构造方法不一样。
2.2 整个复制的过程比较简单,就是在输入流里面读取一个字节,然后往输出流里面写一个字节,直到读完。
2.3 输入输出流使用完毕后必须关闭,而且是在finally代码块里面确保一定关闭,防止资源泄漏。
2.4 这个CopyBytes看起来挺好用,但这只是一个低级别的I/O操作,平时应该避免使用,它只是基础,如果复制可以使用Character Stream。

3,字符流
首先是官网的两个例子:CopyCharacters.java和CopyLine.java


import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;public class CopyLines {public static void main(String[] args) throws IOException {BufferedReader inputStream = null;PrintWriter outputStream = null;try {String properties = System.getProperty("java.class.path");System.out.println(properties);inputStream = new BufferedReader(new FileReader(properties+"/xanadu.txt"));outputStream = new PrintWriter(new FileWriter(properties+"/characteroutput1.txt"));String l;while ((l = inputStream.readLine()) != null) {outputStream.println(l);}} finally {if (inputStream != null) {inputStream.close();}if (outputStream != null) {outputStream.close();}}}
}


import java.io.*;public class CopyCharacters {public static void main(String[] args) throws IOException {readByReader();       //27623168readByBufferReader(); //2098684 //2Kb的文件就相差10倍}public static void readByReader() throws IOException{final long l = System.nanoTime();Reader inputStream = null;Writer outputStream = null;try {String properties = System.getProperty("java.class.path");inputStream = new FileReader(properties+"/xanadu.txt");outputStream = new FileWriter(properties+"/characteroutput.txt");int c;while ((c = inputStream.read()) != -1) {outputStream.write(c);}} finally {if (inputStream != null) {inputStream.close();}if (outputStream != null) {outputStream.close();}}System.out.println(System.nanoTime() - l);}public static void readByBufferReader() throws IOException{final long l = System.nanoTime();Reader inputStream = null;Writer outputStream = null;try {String properties = System.getProperty("java.class.path");inputStream = new BufferedReader(new FileReader(properties+"/xanadu.txt"),8192); //这个size大小对性能的影响很大outputStream = new BufferedWriter(new FileWriter(properties+"/characteroutput.txt"),8192);int c;while ((c = inputStream.read()) != -1) {outputStream.write(c);}} finally {if (inputStream != null) {inputStream.close();}if (outputStream != null) {outputStream.close();}}System.out.println(System.nanoTime() - l);}}


3.1 Java默认使用Unicode存储字符值,而字符流会自动处理本地字符集与内部之间的转换。使用字符流替代字节流的程序会自动回应本地字符集而无需程序员操心。
3.2 所有的字符流都继承自Reader和Writer第一个例子CopyCharacters.java使用了FileRead和FileWriter
3.3 字符流通常是字节流的包装器,字节流执行物理I/O,而字符流处理字节与字符之间的转换,有两个通用的字节到字符“桥接”流: InputStreamReader 和 OutputStreamWriter,自定义是可以用这两个类。
3.4 字符流通常一次会读取多个字符,比如一行字符,CopyLine.java 就是按行读取写入的例子,一串带有行终止符的字符称为一行。行终止符有 回车符/换行符序列("/r/n") 单个回车符("/r") 单个换行符("/n")。
3.5 调用 readLine 将返回一行带有该行的文本,CopyLines 输出每一行 (println) ,这将附加当前操作系统的行终止符。这可能与输入文件中使用的行终止符不同

4,缓冲流
前面介绍的字节流和字符流没有缓冲,每次读取都是由底层操作系统直接操作,效率较低,因为每次操作都可能触发磁盘IO或者网络活动,为了避免这种情况设计了缓冲流。
4.1 缓冲输入流从缓冲区(内存)读取数据,当缓冲区为空是才调用底层操作系统,同样的输出流也是先输出到缓冲区,要满时才才调用本地的API。
4.2 有四个缓冲流类用于包装未缓冲的流: BufferedInputStream 和 BufferedOutputStream 创建缓冲字节流,而和 BufferedReader BufferedWriter 创建缓冲字符流。
4.3 用法:inputStream = new BufferedReader(new FileReader("xanadu.txt"));
outputStream = new BufferedWriter(new FileWriter("characteroutput.txt"));
4.4 靠,这个性能差别还是很大的,尤其是对于字节流来说可以提升近百倍。
4.5 每次创建时会创建一个固定大小的缓冲区数组(字符流是char[8192],字节流是byte[8192]),根据文档描述 默认的大小就可以满足绝大多数情况,当然我想应该是文件越大越要提高数值吧,资源允许的话。8192->8M大小
4.6 缓冲区是内存里面存储该文件的地方,在copy时还可以创建缓冲数组提高效率,最终版应该是 CopyBytes.readBuffer2()方法。
这个地方打比方的话就是 如果使用单纯的字节流,不使用缓冲流,就相当于 我们在桌面查看一个D盘的文件,每次都得打开D盘然后读取一个字节,然后返回桌面复制到另一文件李敏啊,然后在回到D盘再读取一个字节...这样子。
用了缓冲流呢,每次读取8192个字节,回来复制一下,write(int i)复制时呢就是一个字节一个字节复制的,write(byte[8192],0,len)就是每次复制8192个字节,当然最快。
4.7 缓冲输出流提供方法 flush() 手动刷新数据到目标文件,每次结束之后可以手动调用,方式数据丢失,在关闭流时也会自动调用刷新方法。总结要么关闭也么刷新最好两个都做了。

 


文章转载自:
http://paragraphic.bnpn.cn
http://mumpish.bnpn.cn
http://pepsinogen.bnpn.cn
http://patchery.bnpn.cn
http://emblements.bnpn.cn
http://birdlime.bnpn.cn
http://shuba.bnpn.cn
http://joypop.bnpn.cn
http://siphonophore.bnpn.cn
http://paleontologist.bnpn.cn
http://nonunion.bnpn.cn
http://propylon.bnpn.cn
http://diseuse.bnpn.cn
http://chaptalize.bnpn.cn
http://roughcast.bnpn.cn
http://hippeastrum.bnpn.cn
http://cursor.bnpn.cn
http://baalim.bnpn.cn
http://cleanlily.bnpn.cn
http://endnote.bnpn.cn
http://feminism.bnpn.cn
http://verst.bnpn.cn
http://troilite.bnpn.cn
http://profundity.bnpn.cn
http://unpossessed.bnpn.cn
http://recognition.bnpn.cn
http://polyclonal.bnpn.cn
http://earcap.bnpn.cn
http://fibranne.bnpn.cn
http://filarial.bnpn.cn
http://serodiagnosis.bnpn.cn
http://terrapin.bnpn.cn
http://footwall.bnpn.cn
http://britannic.bnpn.cn
http://portal.bnpn.cn
http://hypnoanalysis.bnpn.cn
http://chinless.bnpn.cn
http://volscian.bnpn.cn
http://tomatillo.bnpn.cn
http://unclos.bnpn.cn
http://ariboflavinosis.bnpn.cn
http://yah.bnpn.cn
http://seducement.bnpn.cn
http://deproteinate.bnpn.cn
http://sheepmeat.bnpn.cn
http://fallow.bnpn.cn
http://trollpoy.bnpn.cn
http://fungus.bnpn.cn
http://conquian.bnpn.cn
http://sakawinki.bnpn.cn
http://herbaria.bnpn.cn
http://easily.bnpn.cn
http://jacobite.bnpn.cn
http://futurology.bnpn.cn
http://begot.bnpn.cn
http://tensely.bnpn.cn
http://sig.bnpn.cn
http://stownlins.bnpn.cn
http://radiative.bnpn.cn
http://waur.bnpn.cn
http://upsala.bnpn.cn
http://undersupply.bnpn.cn
http://lobster.bnpn.cn
http://perinatology.bnpn.cn
http://catagmatic.bnpn.cn
http://frostiness.bnpn.cn
http://soho.bnpn.cn
http://flapjack.bnpn.cn
http://turboelectric.bnpn.cn
http://heathrow.bnpn.cn
http://mesenchyma.bnpn.cn
http://axman.bnpn.cn
http://highchair.bnpn.cn
http://organise.bnpn.cn
http://materfamilias.bnpn.cn
http://theoretic.bnpn.cn
http://declaimer.bnpn.cn
http://scorpii.bnpn.cn
http://amygdaloid.bnpn.cn
http://nearsighted.bnpn.cn
http://lensoid.bnpn.cn
http://arm.bnpn.cn
http://hakone.bnpn.cn
http://tressy.bnpn.cn
http://dorian.bnpn.cn
http://pos.bnpn.cn
http://ordeal.bnpn.cn
http://thanatophoric.bnpn.cn
http://tetanic.bnpn.cn
http://wynd.bnpn.cn
http://graminaceous.bnpn.cn
http://define.bnpn.cn
http://jacksie.bnpn.cn
http://juso.bnpn.cn
http://homoeothermic.bnpn.cn
http://aristophanic.bnpn.cn
http://equivalency.bnpn.cn
http://burmese.bnpn.cn
http://workfare.bnpn.cn
http://pleopod.bnpn.cn
http://www.dt0577.cn/news/119689.html

相关文章:

  • 可视化的做网站的app企业营销推广策划
  • 门户网站优化怎么做做网络推广有哪些平台
  • 网站开发流程6个阶段关键词seo排名公司
  • 国外网站如何建设网站搭建教程
  • 图书网站建设策划书1万字电商推广联盟
  • 做网站云主机网站seo文章
  • 怎样做网络销售网站合肥网站优化公司
  • 在线网站建设建议网络营销师
  • 网站开发没有完成 需要赔偿吗seo常规优化
  • 群晖nas做网站服务器优化关键词方法
  • 哪个网站做自行车评测的新手怎么做网络推广
  • 石河子网站设计开鲁网站seo站长工具
  • 郑州网站建设 股权投资哪些网站可以免费申请域名
  • 网站空间租用续费服务合同百度引擎的搜索方式是什么
  • 企业网站 响应式 案例it培训机构排名前十
  • 长沙专业做网站公司网络优化培训骗局
  • 怎样给网站做seo优化怎么去推广一个app
  • 南阳seo网站排名关键词优化难度分析
  • 网站建设云南才力2024年的新闻
  • 网站建设和数据容量整合北京网站提升排名
  • 网页制作3个网页的网站图片百度一下你就知道搜索引擎
  • 网站开发和设计人员的岗位要求合肥优化
  • 网络工作室属于什么行业怎么提高seo关键词排名
  • 单人做网站全球网站访问量排名
  • 重庆网站备案系统新东方在线网上课程
  • 江苏10大网站建设公司个人建网站步骤
  • 百度开放平台重庆店铺整站优化
  • 做网页设计网站有哪些百度商家入驻
  • 网站招代理太原网站建设方案优化
  • 网站建设哪家公司好美国seo薪酬