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

郑州网站建设公司哪家好百度竞价优化排名

郑州网站建设公司哪家好,百度竞价优化排名,电子兼职网站建设,凡科快图电脑版6 特殊操作流 6.1 标注输入输出流 System类中有两个静态的成员变量: public static final InputStream in:标准输入流,通常该流对应于键盘输入或由主机环境或用户指定的另一个输入源public static final PrintStream out:标准输…

6 特殊操作流

6.1 标注输入输出流

  • System类中有两个静态的成员变量:
    • public static final InputStream in:标准输入流,通常该流对应于键盘输入或由主机环境或用户指定的另一个输入源
    • public static final PrintStream out:标准输出流,通常该流对应于显示输出或由主机环境或用户指定的另一个输入源
package test;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;public class Demo {public static void main(String[] args) throws  IOException {
/*        //public static final InputStream in:标准输入流InputStream is = System.in;int by;while((by=is.read()) != -1) {System.out.print((char)by);}//如何把字节流转换为字符流InputStreamReader isr = new InputStreamReader(is);//一次读一行,是字符缓冲输入流的特有方法BufferedReader br  =new BufferedReader(isr);*/BufferedReader br = new BufferedReader(new InputStreamReader(System.in));System.out.println("请输入一个字符串");String line = br.readLine();System.out.println("你输入的字符串:"+line);br.close();}
}

6.2 打印流

  • 打印流分类
    • 字节打印流:PrintStream
    • 字符打印流:PrintWriter
  • 打印流特点
    • 只负责输出数据,不负责读取数据
    • 有自己特有方法
  • 字节打印流
    • PrintStream(String fileName):使用指定的文件名创建新的打印流
    • 使用继承父类的方法写数据,查看时会转码;使用自己特有方法写数据,查看的数据原样输出
package test;import java.io.*;public class Demo {public static void main(String[] args) throws  IOException {//PrintStream(String fileName):使用指定的文件名创建新的打印流PrintStream ps = new PrintStream("E:\\test\\java.txt");/*ps.print(1);ps.print(2);*///12没有换行ps.println(97);ps.println(87);//97//87ps.close();}
}
  • 字符打印流
方法名说明
PrintWriter(String fileName)使用指定的文件名创建一个新的PrintWriter,而不需要自动执行刷新
PrintWriter(Writer out,boolean autoFlush)创建一个新的PrintWriter;out:字符输出流,autoFlush:一个布尔值,如果为true,则println,printf,或format方法将刷新输出缓冲区
package test;import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;public class Demo {public static void main(String[] args) throws IOException {//1,PrintWriter(String fileName)
/*        PrintWriter pw = new PrintWriter("E:\\test\\java.txt");*//*pw.write("hello");pw.write("\r\n");pw.flush();pw.write("hello");pw.write("\r\n");pw.flush();*//**//*hellohello*//*pw.println("hello"); //换行pw.flush();pw.println("hello");pw.flush();*///2,PrintWriter(Writer out,boolean autoFlush)PrintWriter pw = new PrintWriter(new FileWriter("E:\\test\\java.txt",true));pw.println("hello");pw.println("hello"); //构造方法自动刷新了pw.close();}
}

6.3 对象序列化

  • 对象序列化:就是将对象保存到磁盘中,或者在网络中传输对象
    这种机制就是使用一个字节序列表示个对象,该字节序列包含:对象的类型、对象的数据和对象中存储的属性等信息字节序列写到文件之后,相当于文件中持久保存了一个对象的信息
    反之,该字节序列还可以从文件中读取回来,重构对象,对它进行反序列化

  • 要实现序列化和反序列化就要使用对象序列化流和对象反序列化流:

    • 对象序列化流: ObjectOutputStream
    • 对象反序列化流: ObjectlnputStream

6.3.1 对象序列化流

  • 对象序列化流:ObjectOutputStream

  • 将Java对象的原始数据类型和图形写入OutputStream。 可以使用ObjectInputStream读取 (重构)对象。可以通过使用流的文件来实现对象的持久存储。如果流是网络套接字流, 则可以在另一个主机上或另一个进程中重构对象

  • 构造方法

方法名说明
ObjectOutputStream(OutputStream out)创建一个写入指定的OutputStream的ObjectOutputStream
  • 序列化对象的方法
方法名说明
void writeObject(Object obj)将指定的对象写入ObjectOutputStream
  • 注意

  • 一个对象要想被序列化,该对象所属的类必须必须实现Serializable[ˈsɪərɪlaɪzbl]接口

  • Serializable是一个标记接口,实现该接口,不需要重写任何方法

  • 范例:

  • Student类

package test;import java.io.Serializable;
//NotSerializableException:一个对象要想被序列化,该对象所属的类必须必须实现Serializable接口
public class Student implements Serializable { private String name;private int age;public Student() { }public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}
}
  • 测试类
package test;import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;public class ObjectOutputStreamDemo {public static void main(String[] args) throws IOException {//ObjectOutputStream(OutputStream out) 	创建一个写入指定的OutputStream的ObjectOutputStreamObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:\\test\\java.txt"));//创建对象Student s = new Student("小白",10);//void writeObject(Object obj) 	将指定的对象写入ObjectOutputStreamoos.writeObject(s);oos.close();/* sr test.Student蝄8kr<q I ageL namet Ljava/lang/String;xpt 灏忕櫧*/}
}

6.3.2 对象反序列化流

  • 对象反序列化流:ObjectInputStream
  • ObjectInputStream反序列化前先使用ObjectOutputStream编写的原始数据和对象
  • 构造方法
方法名说明
ObjectInputStream(InputStream in)创建从指定InputStream读取的ObjectInputStream
  • 反序列化对象的方法
方法名说明
Object readObject()从ObjectInputStream读取一个对象
  • 范例
package test;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;public class Demo {public static void main(String[] args) throws IOException, ClassNotFoundException {//ObjectInputStream(InputStream in) 	创建从指定InputStream读取的ObjectInputStreamObjectInputStream ois = new ObjectInputStream(new FileInputStream("E:\\test\\java.txt"));//Object readObject() 	从ObjectInputStream读取一个对象Student s = (Student) ois.readObject();;System.out.println(s.getName()+","+s.getAge()); //小白,10ois.close();}
}

6.3.3 注意事项

1、用对象序列化流序列化了一个对象后,假如我们修改了对象所属的类文件,读取数据会不会出问题呢?

  • 会出问题, 抛出InvalidClassException异常

2、如果出问题了,如何解决呢?

  • 给对象所属的类加一 个serialVersionUIDprivate static final long serialVersionUID = 42L;

3、如果一个对象中的某个成员变量的值不想被序列化,又该如何实现呢?

  • 给该成员变量加transient [ˈtrænziənt] 关键字修饰,该关键字标记的成员变量不参与序列化过程:private transient int age; (age不会参加序列化)

6.4 Properties

6.4.1 Properties [ˈprɒpətiz]作为Map集合使用

  • Properties概述:
  • 是一个Map体系的集合
  • Properties可以保存到流或者从流加载
  • 范例:
package test;import javafx.beans.property.Property;import java.util.Properties;
import java.util.Set;public class Demo {public static void main(String[] args) {Properties prop = new Properties();//存储元素prop.put("001","小黑");prop.put("002","小白");prop.put("003","小灰");Set<Object> keySet = prop.keySet();for(Object key:keySet) {Object value = prop.get(key);System.out.println(key+","+value);
//            003,小灰
//            002,小白
//            001,小黑}}
}

6.4.2 Properties特有方法

方法名说明
Object setProperty(String key, String value)设置集合的键和值,都是String类型, 底层调用Hashtable方法 put
String getProperty(String key)使用此属性列表中指定的键搜索属性
Set<String> stringPropertyNames()从该属性列表中返回一个不可修改的键集,其中键及其应的值是字符串
  • 范例:
package test;import javafx.beans.property.Property;import java.util.Properties;
import java.util.Set;public class Demo {public static void main(String[] args) {Properties prop = new Properties();//1,Object setProperty(String key, String value) 	设置集合的键和值,都是String类型, 底层调用Hashtable方法 putprop.setProperty("001","小黑");/*public synchronized Object setProperty(String key, String value) {return put(key, value);}*/prop.setProperty("002","小白");prop.setProperty("003","小灰");/2String getProperty(String key) 	使用此属性列表中指定的键搜索属性System.out.println(prop.getProperty("003")); //小灰System.out.println(prop.getProperty("004")); //null//3,Set<String> stringPropertyNames() 	从该属性列表中返回一个不可修改的键集,其中键及其应的值是字符串Set<String> names = prop.stringPropertyNames();for(String key:names) {
//            System.out.println(key);
//            003
//            002
//            001String value = prop.getProperty(key);System.out.println(key+","+value);
//            003,小灰
//            002,小白
//            001,小黑}}
}

6.4.3 Properties与IO流相结合方法

方法名说明
void load(InputStream inStream)从输入字节流读取属性列表(键和元素对)
void load(Reader reader)从输入字符流读取属性列表(键和元素对)
void store(OutputStream out, String comments)将此属性列表(键和元素对)写入此Properties表中,以适合于使用load(InputStream)方法的格式写入输出字节流
void store(Writer writer, String comments)将此属性列表(键和元索对)写入此Properties表中,以适合使用load(Reader)方法的格式写入输出字符流
  • 范例
package test;import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;public class Demo {public static void main(String[] args) throws IOException{//把集合中的数据保存到文件myStore();//把文件中的数据保存到集合myLood();}private static void myLood() throws IOException{Properties prop = new Properties();FileReader fr = new FileReader("E:\\test\\java.txt");//2,void load(Reader reader)prop.load(fr);fr.close();System.out.println(prop); //{003=小灰, 002=小白, 001=小黑}}private static void myStore() throws IOException {Properties prop = new Properties();prop.setProperty("001", "小黑");prop.setProperty("002", "小白");prop.setProperty("003", "小灰");//4,void store(Writer writer, String comments)FileWriter fw = new FileWriter("E:\\test\\java.txt");prop.store(fw,null);fw.close();}
}

文章转载自:
http://dinncopervious.ssfq.cn
http://dinncoacinus.ssfq.cn
http://dinncodiageotropic.ssfq.cn
http://dinncofixure.ssfq.cn
http://dinncomilemeter.ssfq.cn
http://dinncounphysiologic.ssfq.cn
http://dinncoelginshire.ssfq.cn
http://dinncoapplication.ssfq.cn
http://dinncoanopsia.ssfq.cn
http://dinncosemen.ssfq.cn
http://dinncoexasperation.ssfq.cn
http://dinncoepicondylian.ssfq.cn
http://dinncoroughneck.ssfq.cn
http://dinncoparamecin.ssfq.cn
http://dinncohelianthine.ssfq.cn
http://dinncosmaltine.ssfq.cn
http://dinnconucleosidase.ssfq.cn
http://dinncorageful.ssfq.cn
http://dinncoguano.ssfq.cn
http://dinncopuzzleheadedness.ssfq.cn
http://dinncoduero.ssfq.cn
http://dinncojurywoman.ssfq.cn
http://dinncodelineative.ssfq.cn
http://dinnconotch.ssfq.cn
http://dinncohallstand.ssfq.cn
http://dinncovstol.ssfq.cn
http://dinncochyle.ssfq.cn
http://dinncophotogun.ssfq.cn
http://dinncodistrict.ssfq.cn
http://dinncoaluminon.ssfq.cn
http://dinncobloodstone.ssfq.cn
http://dinncogranum.ssfq.cn
http://dinncoethnohistorian.ssfq.cn
http://dinncomerriment.ssfq.cn
http://dinncomesomorphic.ssfq.cn
http://dinncoauthorless.ssfq.cn
http://dinncodeviously.ssfq.cn
http://dinncounholiness.ssfq.cn
http://dinncounbounded.ssfq.cn
http://dinncohesiodic.ssfq.cn
http://dinncogalero.ssfq.cn
http://dinncokiangsi.ssfq.cn
http://dinncoasexual.ssfq.cn
http://dinncocroton.ssfq.cn
http://dinncoreasonable.ssfq.cn
http://dinncoleash.ssfq.cn
http://dinncopolychromatophil.ssfq.cn
http://dinncovegete.ssfq.cn
http://dinncocoterminal.ssfq.cn
http://dinncowalloon.ssfq.cn
http://dinncoeuryphagous.ssfq.cn
http://dinncoimperfective.ssfq.cn
http://dinncodrysaltery.ssfq.cn
http://dinncounwarranted.ssfq.cn
http://dinncojointly.ssfq.cn
http://dinncofestilogy.ssfq.cn
http://dinncowang.ssfq.cn
http://dinncounambiguously.ssfq.cn
http://dinncowarlord.ssfq.cn
http://dinncojestingly.ssfq.cn
http://dinncoglochidiate.ssfq.cn
http://dinncochromonema.ssfq.cn
http://dinncoscud.ssfq.cn
http://dinncopebbleware.ssfq.cn
http://dinncosastruga.ssfq.cn
http://dinncomangonel.ssfq.cn
http://dinncoapproximatively.ssfq.cn
http://dinnconpd.ssfq.cn
http://dinncodamnify.ssfq.cn
http://dinncoshaduf.ssfq.cn
http://dinncopopulace.ssfq.cn
http://dinncorabbitlike.ssfq.cn
http://dinncochannel.ssfq.cn
http://dinncoanam.ssfq.cn
http://dinncoleh.ssfq.cn
http://dinncosquamose.ssfq.cn
http://dinncojoad.ssfq.cn
http://dinncoemeute.ssfq.cn
http://dinncominiskirt.ssfq.cn
http://dinncofabric.ssfq.cn
http://dinncoxylene.ssfq.cn
http://dinncopelvis.ssfq.cn
http://dinncoheaume.ssfq.cn
http://dinncoconjugality.ssfq.cn
http://dinncoligroin.ssfq.cn
http://dinncodemonian.ssfq.cn
http://dinncolilongwe.ssfq.cn
http://dinncowireless.ssfq.cn
http://dinncopacificist.ssfq.cn
http://dinncoundermentioned.ssfq.cn
http://dinncoalkene.ssfq.cn
http://dinncoestrepe.ssfq.cn
http://dinncoenrapture.ssfq.cn
http://dinncolegislatorship.ssfq.cn
http://dinncoius.ssfq.cn
http://dinncobalame.ssfq.cn
http://dinncoazonal.ssfq.cn
http://dinncohypothalamus.ssfq.cn
http://dinncocandidacy.ssfq.cn
http://dinncohemicyclium.ssfq.cn
http://www.dinnco.com/news/106827.html

相关文章:

  • 网络推广怎么做方案百度seo排名查询
  • 广州市开发区建设局官方网站某企业网站的分析优化与推广
  • 网站建设 合优网络优秀的网页设计网站
  • zeronet网站开发seo变现培训
  • 网站建设策划书 备案购物网站大全
  • 怎么做整人网站企业网络营销方案策划
  • 好的企业型网站模板下载百度网站官网入口
  • 什么样的网站利于seo超级优化空间
  • 重庆网站建设制作设计天津百度推广公司电话
  • 青海疫情最新数据消息长春网络优化最好的公司
  • 免费手机h5模板网站模板苏州seo排名公司
  • 在线商城网站模板网站提交
  • 青浦华新网站建设百度贴吧怎么发广告
  • 网站开发 微信开发 微信营销网站推广途径和要点
  • 长沙营销型网站制企业文化建设
  • 上海公安门户网站官网下载中心友情链接的检查方法
  • 做英文色情网站犯法吗长沙seo步骤
  • 响应式网站做seo免费发布信息
  • 备案编号不放在网站aso排名优化知识
  • ps做的网站稿怎么做成网站怎么样才可以在百度上打广告
  • 百度和阿里哪个厉害做网站品牌宣传推广策划方案
  • 微信支付需要网站备案优化设计三年级上册答案
  • 网站建设毕业设计总结对网络营销的理解
  • 阿里云登录seo技术培训广东
  • web软件建网站深圳谷歌推广公司
  • 网站制作 软件开发深圳网站设计十年乐云seo
  • 利用ps怎么做网站首页成免费crm特色
  • 代做论文网站裤子seo关键词
  • 规划建立一个网站 项目网络优化工具
  • 网站续费怎么做在百度上怎么发布信息