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

建设个b2c网站成都seo排名

建设个b2c网站,成都seo排名,行业网站设计师招聘,机械加工种类一、Java流式输入输出原理Java对于输入输出是以流(Stream)的方式进行的,JDK提供各种各样的“流”类,以获取不同类型的数据。可以理解为将管道插入到文件中,然后从管道获取数据。这个管道外边还可以套管道,外边的管道对数据进行处理…

一、Java流式输入输出原理

Java对于输入输出是以流(Stream)的方式进行的,JDK提供各种各样的“流”类,以获取不同类型的数据。

可以理解为将管道插入到文件中,然后从管道获取数据。这个管道外边还可以套管道,外边的管道对数据进行处理,即套了“处理流”。

二、输入输出流分类

按功能:数据流、处理流

按方向:输入流、输出流

按数据单位:字节流、字符流(2个字节)

Java.io内的流类型继承自一下四种:

2种输入输出 * 2中数据单位:(字节) InputStream、OutputStream、(字符)Reader、Writer

Tip:这里的输入输出是站在程序角度来看的

三、字节流和处理流

字节流:从节点读写数据(如文件、内存)

处理流:套在字节流外,对数据进行处理,为程序提供更强大的读写能力

3.1 字节流类型

类型

字节流(1字节)InputStream

OutputStream

字符流(2字节)

Reader

Writer

File

(File)

FileInputStream

FileOutputStream

FileReader

FileWriter

MemoryArray

(ByteArray/CharArray)

ByteArrayInputStream

ByteArrayOutputStream

CharArrayReader

CharArrayWriter

MemoryString

(String)

-

-

StringReader

StringWriter

Pipe

(Piped)

PipedInputStream

PipedOutputStream

PipedReader

PipedWriter

3.2 处理流类型

处理类型

字节

InputStream/Steam

OutputStream

字符

Reader

Writer

Buffering

BufferedInputStream

BufferedOutputStream

BufferedReader

BufferedWriter

Filtering

FilterInputStream

FilterOutputStream

FilterReader

FilterWriter

bytes和chaacter之间转换

InputStreamReader

OutputStreamWriter

Object Serialization

ObjectInputStream

ObjectOutputStream

Data conversion

DataInputStream

DataOutputStream

Counting

LineNumberInputStream

LineNumberReader

Peeking ahead

PushbackInputStream

PushbackReader

Printing

PrintStream

PrintWriter

四、字节流

InputStream

以字节形式向程序输入数据(8bit)

基本步骤:

  • 新建FileInputStream对象in

  • 打开文件

  • try:new一个文件路径的对象,给in;

  • catch:FileNotFoundException

  • 读取文件

  • try:

  • 判断in.read()是不是-1, 是的话就到头了,就不读了、

  • 关闭in

  • catch:IOException

总结:

以字节的形式挨个读取,输出时要用(char)将ASC码转换出来

FileInputStream对象,new、赋值、.read()、close()

两个异常:FileNotFoundException、IOException

    public static void main(String[] args) {int b = 0;// 新建一个FileInputStream对象FileInputStream in = null;try {// 给FileInputStream赋值in = new FileInputStream("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\number.txt");}catch (FileNotFoundException e){System.out.println("系统找不到指定文件");System.exit(-1);// 系统非正常退出}// 开始读取long num = 0;   // 记录读取了多少个数字try {while ((b = in.read() )!= -1){  // 主要是in.read()System.out.println((char)b);num++;}in.close(); // 关闭输入流System.out.println();System.out.println("总共读了" + num + "个字节");}catch(IOException e){System.out.println("文件读取错误");}}

OutputStream

  • 新建:new一个OutputStream对象,=null

  • 读写:

  • 文件名对应一个对象,赋值给上面新建的对象,这里存在找不到文件的可能(FileNotFoundException)

  • 将东西写到对应的OutputStream中,存在复制失败的可能(IOException)

  • 关闭:各种close(), (也要IOException)

    public static void main(String[] args) {FileInputStream in = null;FileOutputStream out = null;try {// 新建, 以下需catch FileNotFoundExceptionin = new FileInputStream("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\number.txt");out = new FileOutputStream("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\number2.txt");// 读写。 以下需catch IOExceptionint b = 0;while ((b = in.read()) != -1){out.write((char)b);}// 关闭in.close();out.close();}catch(FileNotFoundException e){System.out.println("系统没有找到指定文件");System.exit(-1);}catch (IOException e){System.out.println("读写错误");}

Reader/Writer

注意这里的writer,要写成String.valueOf(i)

因为,int是4个字节,API里写入了低16位的2个字节,忽略了高16位的2个字节。

所以,在输入到文件时不妨吧整形转为char 或者字符串

fw.write(String.valueOf(12));
fw.write(Character.valueOf('1'));

    public static void main(String[] args) {FileReader fr = null;FileWriter fw = null;try {fr = new FileReader("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\number.txt");fw = new FileWriter("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\number3.txt");// 读写for(int i = 0; i < 30; i++){fw.write(String.valueOf(i));}// 关闭fr.close();fw.close();}catch (FileNotFoundException e){System.out.println("找不到指定文件");}catch (IOException e){System.out.println("文件复制错误");}}

五、处理流

5.1 Buffer缓冲流

缓冲是内存中的一块区域,数据在内存中缓冲,然后Flush()立刻写出,需要在close()将缓冲区内容强行输出,否则可能没有输出去。

如果没有buffer,是读一个写一个,很慢;如果有缓冲区,先放内存里,读完后统一写出去,底层会快很多。

  • BufferedInputStream

构造函数 BufferedInputStream( InputStream in) 或者 (InputStream in , int size)

不明白这个mark()和reset()是干啥的。。。

    public static void main(String[] args) {FileInputStream fis = null;try {fis = new FileInputStream("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\number.txt");BufferedInputStream in  = new BufferedInputStream(fis);// mark一下in.mark(2);// 输出do re mi fint c = 0;for (int i = 0; i < 10 && (c = in.read() )!= -1; i++){System.out.println((char)c);}// reset  输出do re mi fin.reset();for (int i = 0; i < 10 && (c = in.read() )!= -1; i++){System.out.println((char)c);}// 关闭in.close();fis.close();}catch (FileNotFoundException e){System.out.println("未找到指定文件");}catch (IOException e){System.out.println("读写错误");}}
  • BufferedReader/ BuffreedWriter

bw.write() 配合 bw.newLine() 向文件里写,最后写操作要进行.flush(),才能写进去,不然在缓存里

br.readLine() 读取整行

bw = new BufferedWriter(new FileWriter("文件路径")) 真的像是包在字符流外边的管道

br = new BufferedReader(new FileReader("文件路径"))

最后要.close()

以上,要配合IOException()的catch操作

    public static void main(String[] args) {BufferedWriter bw = null;BufferedReader br = null;try {bw = new BufferedWriter(new FileWriter("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\numBufferWriter.txt"));String s = null;for(int i = 0; i < 10; i++){s = String.valueOf(Math.random());bw.write(s);bw.newLine();}// 重要!!如果不flush,是写不到文件里的bw.flush();br = new BufferedReader(new FileReader("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\numBufferWriter.txt"));while ((s = br.readLine()) != null){    // 这里是null来判断System.out.println(s);}// 关闭两个处理流bw.close();br.close();}catch (IOException e){System.out.println("系统错误");}}

5.2 转换流

InputStreamReader 和 OutputStreamWriter

如果我们用FileOutputStream流往文件里写东西,是一个字节一个字节的写;外面套上OutputStreamWriter,就是一个字符一个字符的写了。

新建:

OutputStreamWriter osw = new OutputStreamWriter(new一个FileOutputStream对象, "编码格式")

在FileOutputStream中,可以选择是否true, 如果true就不会覆盖原来的,直接接着写

osw.write(内容)

osw.close()

    public static void main(String[] args) {try {// 新建OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\numTransfrom1.txt"));// 写入 .write()osw.write("hello transform");//------编码方式 UTF8System.out.println(osw.getEncoding());// 关闭 .close()osw.close();// 指定编码 new OutputStreamWriter(new FileoutputStream("文件路劲", true),编码格式)// 加了true,就在原有的文件下面接着写,否则就覆盖了// 就用上面的osw就行了osw = new OutputStreamWriter(new FileOutputStream("D:\\工作\\编程\\after 2022.11\\KuangShengShuo\\src\\com\\baidu\\File\\numTransfrom2.txt",true),"ISO8859_1");osw.write("hello world again!");System.out.println(osw.getEncoding());osw.close();}catch (IOException e){System.out.println("系统错误");}}

文章转载自:
http://dinncoengarcon.tpps.cn
http://dinncotoxic.tpps.cn
http://dinncoolfactometer.tpps.cn
http://dinncoparanoea.tpps.cn
http://dinncowust.tpps.cn
http://dinncoornament.tpps.cn
http://dinncocircumcolumnar.tpps.cn
http://dinncocolicine.tpps.cn
http://dinnconork.tpps.cn
http://dinncoangulately.tpps.cn
http://dinncobonbonniere.tpps.cn
http://dinncogardyloo.tpps.cn
http://dinncoextravagance.tpps.cn
http://dinncomethodic.tpps.cn
http://dinncodetonable.tpps.cn
http://dinncodespot.tpps.cn
http://dinncoaftertime.tpps.cn
http://dinncolinearise.tpps.cn
http://dinncometallography.tpps.cn
http://dinncotetraspermous.tpps.cn
http://dinncoheterophony.tpps.cn
http://dinncoshinar.tpps.cn
http://dinncosiphunculated.tpps.cn
http://dinncotsushima.tpps.cn
http://dinncoxyphoid.tpps.cn
http://dinncofluff.tpps.cn
http://dinncopirogue.tpps.cn
http://dinncolasing.tpps.cn
http://dinncodiplomatise.tpps.cn
http://dinncoequiponderate.tpps.cn
http://dinncoholocryptic.tpps.cn
http://dinncomagnanimous.tpps.cn
http://dinncostiffly.tpps.cn
http://dinncoquintuplicate.tpps.cn
http://dinncocoo.tpps.cn
http://dinncotsp.tpps.cn
http://dinncorejudge.tpps.cn
http://dinncoeaprom.tpps.cn
http://dinncoreminiscent.tpps.cn
http://dinncosuboffice.tpps.cn
http://dinncoused.tpps.cn
http://dinncobarbacan.tpps.cn
http://dinncovection.tpps.cn
http://dinncoindustrious.tpps.cn
http://dinnconorthing.tpps.cn
http://dinncocounterclockwise.tpps.cn
http://dinncohitter.tpps.cn
http://dinncomikvah.tpps.cn
http://dinncovisby.tpps.cn
http://dinncostramonium.tpps.cn
http://dinncocaducary.tpps.cn
http://dinncophlebotomist.tpps.cn
http://dinncoskandalon.tpps.cn
http://dinncojawline.tpps.cn
http://dinncochronotron.tpps.cn
http://dinncoabstractionism.tpps.cn
http://dinncohaematin.tpps.cn
http://dinncoserried.tpps.cn
http://dinncolacking.tpps.cn
http://dinncorelucent.tpps.cn
http://dinncoasphyxiant.tpps.cn
http://dinncoinoculation.tpps.cn
http://dinncomailbag.tpps.cn
http://dinncoknight.tpps.cn
http://dinncolichenification.tpps.cn
http://dinncopatellar.tpps.cn
http://dinncosochi.tpps.cn
http://dinncofrgs.tpps.cn
http://dinncoanomy.tpps.cn
http://dinncopresternum.tpps.cn
http://dinncometonymical.tpps.cn
http://dinncoideography.tpps.cn
http://dinncorunabout.tpps.cn
http://dinncounacceptable.tpps.cn
http://dinncoforfarshire.tpps.cn
http://dinncofonduta.tpps.cn
http://dinncogiftwrapping.tpps.cn
http://dinncodirtiness.tpps.cn
http://dinncohire.tpps.cn
http://dinncorecheat.tpps.cn
http://dinncoupbore.tpps.cn
http://dinncobezant.tpps.cn
http://dinncodiminish.tpps.cn
http://dinncoriproaring.tpps.cn
http://dinncojusticiar.tpps.cn
http://dinncopinouts.tpps.cn
http://dinncofiliale.tpps.cn
http://dinncodrivership.tpps.cn
http://dinncoprodigally.tpps.cn
http://dinncoperigynous.tpps.cn
http://dinncopoetics.tpps.cn
http://dinncodomestos.tpps.cn
http://dinncoblanche.tpps.cn
http://dinncoduskily.tpps.cn
http://dinncoestrangement.tpps.cn
http://dinncopolygamical.tpps.cn
http://dinncobeery.tpps.cn
http://dinncomontan.tpps.cn
http://dinncorheinland.tpps.cn
http://dinncojacobean.tpps.cn
http://www.dinnco.com/news/92466.html

相关文章:

  • 徐州vi设计公司厦门seo网站优化
  • 室内设计师网站有哪些网络引流怎么做啊?
  • 做专业维修网站店面怎么做位置定位
  • 美国二手表网站百度提交
  • 网站开发技能深圳网络运营推广公司
  • 重庆南坪网站建设公司佛山seo联系方式
  • 从网络安全角度考量请写出建设一个大型电影网站规划方案青岛网络推广公司排名
  • 可爱风格网站电商引流推广方法
  • vps服务器中的网站不显示图片百度合作平台
  • wordpress安卓aso优化是什么意思
  • 南京做网站seo百度推广
  • 网站优化原理汕头seo网站建设
  • saas平台seo网站推广多少钱
  • 医院网站后台管理系统登录如何搭建个人网站
  • PK10如何自己做网站百度合伙人官网app
  • 嘉兴建设局网站广州aso优化
  • 有网站后台模板如何做数据库怎么找需要做推广的公司
  • 自己做的网站怎么接入网页游戏谷歌浏览器官网手机版
  • 个人网站如何获得流量上海快速优化排名
  • 公司注册地址在外地却在本地经营汉川seo推广
  • 装饰公司网站北京网站优化指导
  • wordpress前台代码编辑器上海网站seo公司
  • 规划建立一个网站百度快照网址
  • 嘉兴公司制作网站的如何营销
  • 个人 申请域名做网站中山seo推广优化
  • wordpress自动同步插件怀来网站seo
  • 网站建设 价格百度推广效果怎么样
  • 吉化北建公司官网西青seo
  • 做网站原创要多少钱外贸快车
  • 做网站交互demo工具唐山seo优化