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

学校英文版网站建设方案高端大气的的网站

学校英文版网站建设方案,高端大气的的网站,wordpress 十万条信息,centos下xampp装载wordpress#xff08;注#xff1a;本篇文章分为两个部分#xff0c;如果想更为深刻的了解IO#xff0c;请关注下一篇#xff1b;欢迎大家学习讨论和批评指正#xff09; IO1 作用 将数据在虚拟机内存和本地磁盘之间进行传输 I#xff1a;input 输入 O#xff1a;output 输…注本篇文章分为两个部分如果想更为深刻的了解IO请关注下一篇欢迎大家学习讨论和批评指正 IO1 作用 将数据在虚拟机内存和本地磁盘之间进行传输 Iinput 输入 Ooutput 输出 流 相当于管道作用为进行数据传输 分类 从传输方向上看 输入流本地磁盘的数据向JVM传输输出流JVM数据向本地磁盘传输 从传输单位上看 字节流以字节为单位进行数据传输。可以传输任意类型的数据如文本、图片、视频、音频等字符流以字符为单位进行数据传输。只能传输文本类型的数据如.txt、.java、.html等 从传输功能上看 节点流具有传输功能和意义的流过滤流没有传输功能用来给节点流增强传输能力或增加附加功能 字节流 输入流InputStream 抽象父类输出流OutputStream 抽象父类 输入流 节点流FileInputStream 创建 FileInputStream fisnew FileInputStream(本地的文件路径);路径 绝对路径以电脑磁盘为基点的完整路径 FileInputStream fis new FileInputStream(D:\\test\\a.txt); FileInputStream fis new FileInputStream(D:/test/a.txt);相对路径以当前项目路径为基点的路径前提是文件必须在项目下 FileInputStream fis new FileInputStream(file\\a.txt); FileInputStream fis new FileInputStream(file/a.txt);路径书写必须截至至文件 文件必须存在否则抛出异常 常用方法 void close()关闭流链接释放相关资源。(每个流中都有)int read(): 读取一个字节返回,读取到达末尾,返回-1int read(byte[] b): 尝试读取数组长度的数据至数组中, 返回实际读取个数.读取到达末尾,返回-1 package com.by.test;import java.io.FileInputStream;public class TestFIS {public static void main(String[] args)throws Exception {// FileInputStream fis new FileInputStream(D:\\test\\a.txt);// FileInputStream fis new FileInputStream(D:/test/a.txt);// FileInputStream fis new FileInputStream(C:\\Users\\Administrator\\IdeaProjects\\Chp16\\file\\a.txt);FileInputStream fis new FileInputStream(file\\a.txt);//FileInputStream fis new FileInputStream(file/a.txt);//读取一个字节//利用循环读取文件所有内容while (true) {//先接收本次读取内容int n fis.read();//判断读取是否到达末尾if (n -1) {break;}//未到达末尾,输出查看System.out.println((char) n);}//利用read(byte[])循环读取文件所有内容while (true) {byte[] bs new byte[3];//接收本次读取结果int n fis.read(bs);//判断读取是否到达末尾if (n -1) {break;}//遍历数组查看本次读取结果for (int i 0; i bs.length; i) {System.out.println(bs[i]);}}//关流fis.close();System.out.println(执行成功);} }输出流 节点流:FileOutputStream 创建 FileOutputStream fosFileOutputStream(本地的文件路径,true|false);如果文件不存在,会自动创建 无法创建文件夹 true表示数据追加,false表示数据覆盖 默认是false 常用方法 void flush(): 刷新缓冲区,所有输出流中都具备该方法void write(int ): 向目标文件写入一个字节void write(byte[] ): 向目标文件写入一个数组的数据 package com.by.test;import java.io.FileOutputStream;public class TestFOS {public static void main(String[] args)throws Exception {FileOutputStream fosnew FileOutputStream(file/b.txt);//写入一个字节fos.write(65);fos.write(66);fos.write(67);//写入一个数组String str abcdefg123456;byte[] bs str.getBytes();fos.write(bs);//关流fos.close();System.out.println(执行成功!);} }标准异常处理 JDK7.0之后,提供了自动关流的语法结构,简化了finally的工作内容 try(//需要自动关流的创建语句 ){}catch(){}原理: JDK7.0之后,所有的流都默认实现了AutoCloseable接口,该接口中提供了自动关流所需的close方法 package com.by.test;import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException;public class TestFOS2 {public static void main(String[] args) {try (FileOutputStream fos new FileOutputStream(file/b.txt);){//写入一个字节fos.write(65);fos.write(66);fos.write(67);//写入一个数组String str abcdefg123456;byte[] bs str.getBytes();fos.write(bs);} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败);} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}System.out.println(执行成功!);} }文件复制 原理: 先将文件A中的内容读取到JVM中,再从JVM中将读取内容写入到文件B, 借助JVM来实现A与B之间的数据复制 先读后写 package com.by.test;import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException;public class TestFileCopy {public static void main(String[] args) {copy1();copy2();}/*** 一次复制一个字节*/public static void copy1(){try (//创建输出节点流-复制到的文件路径FileOutputStream fosnew FileOutputStream(d:/test/2.pdf);//创建输入节点流-被复制的文件路径FileInputStream fisnew FileInputStream(d:/test/1.pdf)) {//先循环读取文件所有内容while (true) {int n fis.read();if (n -1) {break;}//将本次读取的字节写入到目标文件fos.write(n);}System.out.println(复制成功!);} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}}/*** 一次复制一个字节数组*/public static void copy2(){try (//创建输出节点流-复制到的文件路径FileOutputStream fosnew FileOutputStream(d:/test/3.pdf);//创建输入节点流-被复制的文件路径FileInputStream fisnew FileInputStream(d:/test/1.pdf)) {//先循环读取文件所有内容while (true) {//创建数组byte[] bs new byte[1024];//读取一个数组的数据int n fis.read(bs);if (n -1) {break;}//将数组中的数据写入到目标文件fos.write(bs);}System.out.println(复制成功!);} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}} } 缓冲过滤流 BufferedInputStream: 输入缓冲过滤流BufferedOutputStream: 输出缓冲过滤流 创建 BufferedInputStream bisnew BufferedInputStream(fis对象); BufferedOutputStream bosnew BufferedOutputStream(fos对象);作用 拥有一个内置的数据缓冲区, 文件数据将对接至数据缓冲区中,在缓冲区刷新或关闭时再将内部内容一并的给到目标文件 /*** 一次复制一个字节缓冲过滤流*/public static void copy3(){try (//创建输出节点流-复制到的文件路径FileOutputStream fosnew FileOutputStream(d:/test/4.pdf);//创建输入节点流-被复制的文件路径FileInputStream fisnew FileInputStream(d:/test/1.pdf);//添加缓冲过滤流BufferedOutputStream bosnew BufferedOutputStream(fos);BufferedInputStream bisnew BufferedInputStream(fis)) {//先循环读取文件所有内容while (true) {int n bis.read();if (n -1) {break;}//将本次读取的字节写入到目标文件bos.write(n);}System.out.println(复制成功!);} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}}使用 如果先写后读,需要在写入完成后刷新缓冲区才能保证读取的正常进行 调用flush():强刷缓冲区 (推荐)调用close(): 关流之前也会刷新缓冲区 关流时外层过滤流关闭内层节点流会一并关闭 package com.by.test;import java.io.*;public class TestBuffered {public static void main(String[] args) {try(//输出BufferedOutputStream bosnew BufferedOutputStream(new FileOutputStream(file/a.txt));//输入BufferedInputStream bisnew BufferedInputStream(new FileInputStream(file/a.txt))){//先写bos.write(abcd.getBytes());//刷新缓冲区bos.flush(); //bos.close();//再读while (true) {int n bis.read();if (n -1) {break;}System.out.println((char) n);}}catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}} }对象过滤流 ObjectInputStream 对象输入过滤流ObjectOutputStream 对象输出过滤流附加功能1: 读写基本类型附加功能2: 读写引用类型 读写基本类型 读取: ois.readXxx() 写入: oos.writeXxx(值);注: Xxx对应的为基本类型名,首字母大写由于对象过滤流底层嵌套了缓冲区,所以先写后读操作时,仍然需要在写入完成后刷新缓冲区为了保证数据的安全性,所以在写入时数据会根据魔数机制对其加密,在读取时在进行解密 package com.by.test;import java.io.*;public class TestObject_Double {public static void main(String[] args) {try (//输出流ObjectOutputStream oosnew ObjectOutputStream(new FileOutputStream(file/c.txt));//输入流ObjectInputStream oisnew ObjectInputStream(new FileInputStream(file/c.txt))) {//先写oos.writeDouble(10.5);//强刷缓冲区oos.flush();//读取System.out.println(ois.readDouble());} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);e.printStackTrace();} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}} }读写引用类型 读取: Object ois.readObject() 读取到达末尾,抛出EOFException异常 写入: oos.writeObject(对象) 可以自动刷新缓冲区,所以先写后读时无需进行flush读写String package com.by.test;import java.io.*;public class TestObject_String {public static void main(String[] args) {try (//输出流ObjectOutputStream oosnew ObjectOutputStream(new FileOutputStream(file/c.txt));//输入流ObjectInputStream oisnew ObjectInputStream(new FileInputStream(file/c.txt))) {//先写oos.writeObject(床前明月光);oos.writeObject(疑是地上霜);oos.writeObject(举头望明月);oos.writeObject(低头思故乡);//后读while (true) {try {String s (String) ois.readObject();System.out.println(s);} catch (EOFException e) {//读取到达末尾,跳出循环break;}}} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);e.printStackTrace();} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}} }读写自定义类型 自定义类必须实现Serializable接口表示允许被序列化否则IO流没有读写权限 序列化拆分对象信息的过程 反序列化通过信息组装对象的过程 将属性通过transient修饰符修饰则可以防止其参与序列化 如果对象中有自定义类型的属性则必须使该属性类型也实现序列化接口或者通过transient修饰符对其修饰 package com.by.entity;import java.io.Serializable;public class Student implements Serializable {private String name;private int age;//防止被序列化private transient double score;// private Teacher tea; //省略getter、setter、构造、toString } package com.by.test;import com.by.entity.Student;import java.io.*;public class TestObject_Student {public static void main(String[] args) {try (//输出流ObjectOutputStream oosnew ObjectOutputStream(new FileOutputStream(file/c.txt));//输入流ObjectInputStream oisnew ObjectInputStream(new FileInputStream(file/c.txt))) {//先写oos.writeObject(new Student(zhangsan, 20, 88.5));//后读System.out.println((Student)ois.readObject());} catch (FileNotFoundException e) {System.out.println(文件路径不正确);} catch (IOException e) {System.out.println(读写失败!);e.printStackTrace();} catch (Exception e) {System.out.println(未知异常!);e.printStackTrace();}} }怎么理解输出语句 System是类库中的工具类out为该工具类中的静态属性类型为标准输出流类型print和println系列方法是该流中提供的写入方法作用为向控制台写入一个内容 今日掌握 流的分类文件复制的源码字节复制缓冲过滤流对象过滤流读写自定义类型
http://www.pierceye.com/news/252170/

相关文章:

  • 东营房地产网站建设wordpress文章关键字替换
  • 网站制作哪里好薇网站建设中最重要的环节是
  • 中山做营销型网站石家庄招投标公共服务平台官网
  • 修改wordpress的站点地址WordPress全屏图
  • 购物网站建设源码wordpress如何更改页脚背景颜色
  • 大型网站开发技术注册网站代码
  • 网站建设管理报告网站建设专家北京注安
  • 免费网站生成软件网站备案中的网站名称
  • 桐庐做网站手机里编辑 Wordpress
  • 外网怎么进入萧山网站优化
  • 做资源下载网站好吗婚恋网站建设公司排名
  • 网站后台管理系统管理员登录wordpress页面模板下载地址
  • 网站用户体验网络科技公司网站制作
  • seo中文全称是什么360搜索怎么做网站自然优化
  • 青岛网站建设技术外包文本资料分享网站 建设
  • 做好网站建设工作wordpress转发微信缩略图
  • 马鞍山网站开发流程设计师免费资源导航
  • 成功的网站不仅仅是优化排视频网站建设应该注意什么
  • 如何制作网站和软件查询关键词密度网站的网址有哪些
  • 网站服务器查询平台贵阳网站改版
  • 怎样查看网站总浏览量寿县有做网站开发的吗
  • 东莞网站建设价格价格网建企业
  • 做播放器电影网站需要多少钱6网络工程师证
  • dw怎么做网站标题图标网站建设进度表 免费下载
  • 西安哪些做网站的公司好做电子商务网站的意义
  • 圣融网站建设包装设计网站是什么样子的
  • 网站建设的利润设计宝
  • 厦门网站制作案例dede做手机网站
  • 网站建设 环保 图片重庆信息网
  • 做网站的主流软件珠海网站建设珠海