欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

java語(yǔ)言

計(jì)算機(jī)二級(jí)JAVA考試要點(diǎn)復(fù)習(xí)

時(shí)間:2025-06-03 21:31:28 java語(yǔ)言 我要投稿

計(jì)算機(jī)二級(jí)JAVA考試要點(diǎn)復(fù)習(xí)

  知識(shí)就是靠積累起來的,經(jīng)驗(yàn)也是積累起來的。以下是百分網(wǎng)小編整理的計(jì)算機(jī)二級(jí)JAVA考試要點(diǎn)復(fù)習(xí),歡迎學(xué)習(xí)!

計(jì)算機(jī)二級(jí)JAVA考試要點(diǎn)復(fù)習(xí)

  一、對(duì)象流

  串行化:對(duì)象通過寫出描述自己狀態(tài)的數(shù)值來記述自己的過程叫串行話

  對(duì)象流:能夠輸入輸出對(duì)象的流

  將串行化的對(duì)象通過對(duì)象流寫入文件或傳送到其他地方

  對(duì)象流是在普通流上加了傳輸對(duì)象的功能,所以構(gòu)造對(duì)象流時(shí)要先構(gòu)造普通文件流

  注意:只有實(shí)現(xiàn)了Serializable接口的類才能被串行化

  例子:

  import java.io.*;

  class Student implements Serializable{

  private String name;

  private int age;

  public Student(String name,int age){

  this.name=name;

  this.age=age;

  }

  public void greeting(){

  System.out.println("hello ,my name is "+name);

  }

  public String toString(){

  return "Student["+name+","+age+"]";

  }

  }

  public class ObjectOutTest{

  public static void main(String args[]){

  ObjectOutputStream oos=null;

  try{

  oos=new ObjectOutputStream(

  new FileOutputStream("student.txt"));

  Student s1=new Student("Jerry",24);

  Student s2=new Student("Andy",33);

  oos.writeObject(s1);

  oos.writeObject(s2);

  }catch(Exception e){

  e.printStackTrace();

  }finally{

  if(oos!=null)

  try{

  oos.close();

  }catch(Exception e){

  e.printStackTrace();

  }

  }

  }

  }

  import java.io.*;

  public class ObjectInTest{

  public static void main(String args[]){

  ObjectInputStream ois=null;

  Student s=null;

  try{

  ois=new ObjectInputStream(

  new FileInputStream("student.txt"));

  System.out.println("--------------------");

  s=(Student)ois.readObject();

  System.out.println(s);

  s.greeting();

  System.out.println("--------------------");

  s=(Student)ois.readObject();

  System.out.println(s);

  s.greeting();

  }catch(Exception e){

  e.printStackTrace();

  }finally{

  if(ois!=null)

  try{

  ois.close();

  }catch(Exception e){

  e.printStackTrace();

  }

  }

  }

  }

  二、字符流 InputStreamReader/OutputStreamWriter

  上面的幾種流的單位是 byte,所以叫做字節(jié)流,寫入文件的都是二進(jìn)制字節(jié),我們無法直接看,下面要學(xué)習(xí)的是字節(jié)流

  Java采用 Unicode 字符集,每個(gè)字符和漢字都采用2個(gè)字節(jié)進(jìn)行編碼,ASCII 碼是 Unicode 編碼的自集

  InputStreamReader 是 字節(jié)流 到 字符橋的橋梁 ( byte->char 讀取字節(jié)然后用特定字符集編碼成字符)

  OutputStreamWriter是 字符流 到 字節(jié)流的橋梁 ( char->byte )

  他們是在字節(jié)流的基礎(chǔ)上加了橋梁作用,所以構(gòu)造他們時(shí)要先構(gòu)造普通文件流

  我們常用的是:

  BufferedReader 方法:readLine()

  PrintWriter 方法:println()

  例子:

  import java.io.*;

  public class PrintWriterTest{

  public static void main(String args[]){

  PrintWriter pw=null;

  try{

  pw=new PrintWriter(

  new OutputStreamWriter(

  new FileOutputStream("bufferedwriter.txt")));

  pw.println("hello world");

  }catch(Exception e){

  e.printStackTrace();

  }finally{

  if(pw!=null)

  try{

  pw.close();

  }catch(Exception e){

  e.printStackTrace();

  }

  }

  }

  }

  import java.io.*;

  public class BufferedReaderTest{

  public static void main(String args[]){

  BufferedReader br=null;

  try{

  br=new BufferedReader(

  new InputStreamReader(

  new FileInputStream("bufferedwriter.txt")));

  System.out.println(br.readLine());

  }catch(Exception e){

  e.printStackTrace();

  }finally{

  if(br!=null)

  try{

  br.close();

  }catch(Exception e){

  e.printStackTrace();

  }

  }

  }

  }

【計(jì)算機(jī)二級(jí)JAVA考試要點(diǎn)復(fù)習(xí)】相關(guān)文章:

計(jì)算機(jī)二級(jí)考試java要點(diǎn)知識(shí)復(fù)習(xí)07-05

計(jì)算機(jī)二級(jí)Java要點(diǎn)知識(shí)的復(fù)習(xí)09-28

2017計(jì)算機(jī)二級(jí)JAVA要點(diǎn)知識(shí)復(fù)習(xí)11-06

2017年java考試要點(diǎn)復(fù)習(xí)題08-10

2017計(jì)算機(jī)二級(jí)考試JAVA考前復(fù)習(xí)題08-05

二級(jí)C語(yǔ)言考試復(fù)習(xí)五要點(diǎn)10-28

二級(jí)建造師考試復(fù)習(xí)要點(diǎn)09-04

計(jì)算機(jī)二級(jí)考試JAVA試題08-04

計(jì)算機(jī)二級(jí)JAVA考試構(gòu)建JAVA程序201710-02