<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    BloveSaga

    在希臘帕爾納斯山南坡上,有一個馳名世界的戴爾波伊神托所,在它的入口處的巨石上赫然銹刻著這樣幾個大字: 認識你自己!

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      34 隨筆 :: 12 文章 :: 122 評論 :: 0 Trackbacks

    ? 編碼:將一個Unicode碼轉換為本地字符表示的過程為編碼。
    ? 解碼:將一個字節轉換為一個字符(用Unicode表示),這個過程叫解碼。
    ??????? [簡單的說去獲取一個Unicode碼就是解碼]
    ?code:

    import java.util.*;
    import java.nio.charset.*;
    class CharsetTest
    {
    ?public static void main(String[] args)throws Exception
    ?{
    ??/*
    ??Map m=Charset.availableCharsets();
    ??Set names=m.keySet();
    ??Iterator it =names.iterator();
    ??while(it.hasNext())
    ??{
    ???System.out.println(it.next());
    ??}
    ??*/
    ??Properties pps=System.getProperties();
    ??//pps.list(System.out);
    ??pps.put("file.encoding","ISO-8859-1");
    ??int data;
    ??byte[] buf=new byte[100];
    ??int i=0;
    ??while((data=System.in.read())!='q')
    ??{
    ???buf[i]=(byte)data;
    ???i++;
    ??}
    ??String str=new String(buf,0,i);
    ??//String strGBK=new String(str.getBytes("ISO-8859-1"),"GBK");
    ??//System.out.println(strGBK);
    ??System.out.println(str);
    ?}
    }

    ?

    ???? RandomAccessFile

    ? RandomAccessFile類同時實現了DataInput和DataOutput接口,提供了對文件隨機存取的功能,
    ? 利用這個類可以在文件的任何位置讀取或寫入數據。
    ? RandomAccessFile類提供了一個文件指針,用來標志要進行讀寫操作的下一位數據的位置。

    ?
    ?code:
    import java.io.*;
    class RandomFileTest
    {
    ?public static void main(String[] args)throws Exception
    ?{
    ??Student s1 = new Student(1,"zhangsan",98.5);
    ??Student s2 = new Student(2,"lisi",90.5);
    ??Student s3 = new Student(3,"wangwu",78.5);
    ??
    ??RandomAccessFile rsf=new RandomAccessFile("student.txt","rw");? //存取模式rw
    ??s1.WriteStudent(rsf);
    ??s2.WriteStudent(rsf);
    ??s3.WriteStudent(rsf);
    ??
    ??Student s =new Student();
    ??rsf.seek(0); //把文件指針移到文件首
    ??for(long i=0;i<rsf.length();i=rsf.getFilePointer())
    ??{
    ???s.ReadStudent(rsf);
    ???System.out.println(s.num+":"+s.name+":"+s.score);
    ??}
    ??rsf.close();
    ?}
    }

    class Student
    {
    ?int num;
    ?String name;
    ?double score;
    ?Student()
    ?{
    ??
    ?}
    ?Student(int num,String name,double score)
    ?{
    ??this.num=num;
    ??this.name=name;
    ??this.score=score;
    ?}
    ?public void WriteStudent(RandomAccessFile raf)throws Exception
    ?{
    ??raf.writeInt(num);
    ??raf.writeUTF(name);
    ??raf.writeDouble(score);
    ?}
    ?public void ReadStudent(RandomAccessFile raf)throws Exception
    ?{
    ??raf.readInt();
    ??raf.readUTF();
    ??raf.readDouble();??
    ?}
    }


    ?????????? 對象序列化

    ?.將對象轉換為字節流保存起來,并在日后還原這個對象,這種機制叫做對象序列化。
    ?.將一個對象保存到永久存儲設備上稱為持續性。
    ?.一個對象要想能夠實現序列化,必須實現Serializable接口或Externalizable接口。
    ?.當一個對象被序列化時,只保存對象的非靜態成員變量,不能保存任何的成員變量和靜態的
    ? 成員變量。
    ?.如果一個對象的成員變量是一個對象,那么這個對象的數據成員也會被保存。
    ?.如果一個可序列化的對象包含對某個不可序列化的對象的引用,那么整個序列化操作將會失敗,
    ? 并且會拋出一個NotSerializableException。我們可以將這個引用標記為transient,那么對象
    ? 仍然可以序列化。

    ?code:
    import java.io.*;
    class ObjectSerialTest
    {
    ?public static void main(String[] args)throws Exception
    ?{
    ??Employee e1 = new Employee("zhangsan",20,2800.50);
    ??Employee e2 = new Employee("lisi",22,25000.50);
    ??Employee e3 = new Employee("wangwu",23,12800.50);
    ??Employee e4 = new Employee("blovesaga",22,3800.50);
    ??
    ??FileOutputStream fos=new FileOutputStream("employee.txt");
    ??ObjectOutputStream oos=new ObjectOutputStream(fos);
    ??oos.writeObject(e1);
    ??oos.writeObject(e2);
    ??oos.writeObject(e3);
    ??oos.writeObject(e4);
    ??oos.close();
    ??
    ??FileInputStream fis = new FileInputStream("employee.txt");
    ??ObjectInputStream ois =new ObjectInputStream(fis);
    ??Employee e;
    ??for(int i=0;i<4;i++)
    ??{
    ???e=(Employee)ois.readObject();
    ???System.out.println(e.name+":"+e.age+":"+e.salary);
    ??}
    ??ois.close();
    ?}
    }

    class Employee implements Serializable
    {
    ?String name;
    ?int age;
    ?double salary;
    ?transient Thread t1 =new Thread();
    ?Employee(String name,int age,double salary)
    ?{
    ??this.name=name;
    ??this.age=age;
    ??this.salary=salary;
    ?}
    ?//可以寫private void readObject()方法來控制我們自己想要實現的
    ?private void writeObject(java.io.ObjectOutputStream oos)throws Exception
    ?{
    ??//例如我們自己寫想要顯示的順序和那些需要顯示
    ??oos.writeInt(age);
    ??oos.writeUTF(name);
    ??System.out.println("Write Object");
    ?}
    ?private void readObject(java.io.ObjectInputStream ois)throws Exception
    ?{
    ??//按照寫入的順序來讀取
    ??age=ois.readInt();
    ??name=ois.readUTF();
    ??System.out.println("Read Object");
    ?}
    }

    posted on 2006-06-11 21:27 藍色Saga 閱讀(148) 評論(0)  編輯  收藏 所屬分類: Basic Study for JAVA
    主站蜘蛛池模板: 亚洲日韩一区二区一无码| 亚洲va国产va天堂va久久| 永久久久免费浮力影院| 夫妻免费无码V看片| 免费又黄又爽又猛的毛片 | 国产一区二区三区免费| 在线日本高清免费不卡| 好吊妞视频免费视频| 亚洲综合精品伊人久久| 美女视频黄a视频全免费网站色窝| 精品亚洲视频在线观看| 亚洲精品国产情侣av在线| 亚洲精品无码你懂的| 国产精品无码一二区免费 | 国色精品卡一卡2卡3卡4卡免费| 国产在线19禁免费观看| 特级毛片aaaa级毛片免费| 精品视频在线免费观看| 亚洲成人中文字幕| 久久99久久成人免费播放| 国内免费高清在线观看| 水蜜桃亚洲一二三四在线| 亚洲啪啪免费视频| 国产成人精品日本亚洲网站| 久久久久久亚洲精品无码| 中文字幕在线免费| 亚洲色大成网站www永久网站| 国产黄色片在线免费观看| 亚洲色欲色欲www| 久久精品国产免费观看三人同眠| 亚洲一区在线免费观看| 在线看片免费人成视久网| 亚洲熟妇无码AV不卡在线播放| 在线免费观看国产视频| 成全视频在线观看免费| 亚洲午夜日韩高清一区| 在线视频亚洲一区| 国产成人精品免费久久久久| 国产亚洲老熟女视频| 在线视频精品免费| 亚洲一级毛片免费在线观看|