国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - java 對(duì)象輸入輸出流讀寫(xiě)文件的操作實(shí)例

java 對(duì)象輸入輸出流讀寫(xiě)文件的操作實(shí)例

2020-12-08 14:52nello Java教程

這篇文章主要介紹了java 對(duì)象輸入輸出流讀寫(xiě)文件的操作實(shí)例的相關(guān)資料,這里使用實(shí)現(xiàn)Serializable接口,需要的朋友可以參考下

java 對(duì)象輸入輸出讀寫(xiě)文件的操作實(shí)例

java 支持對(duì)對(duì)象的讀寫(xiě)操作,所操作的對(duì)象必須實(shí)現(xiàn)Serializable接口。

實(shí)例代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package vo;
 
import java.io.Serializable;
 
public class Animal implements Serializable {
  private static final long serialVersionUID = 1L;
  private String name;
  private Integer weight;
  private String color;
  private String type;
  private Integer age;
  private Integer lifetime;
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public Integer getWeight() {
    return weight;
  }
  public void setWeight(Integer weight) {
    this.weight = weight;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  public String getType() {
    return type;
  }
  public void setType(String type) {
    this.type = type;
  }
  public Integer getAge() {
    return age;
  }
  public void setAge(Integer age) {
    this.age = age;
  }
  public Integer getLifetime() {
    return lifetime;
  }
  public void setLifetime(Integer lifetime) {
    this.lifetime = lifetime;
  }
  public Animal(String name, Integer weight, String color, String type, Integer age, Integer lifetime) {
    super();
    this.name = name;
    this.weight = weight;
    this.color = color;
    this.type = type;
    this.age = age;
    this.lifetime = lifetime;
  }
  @Override
  public String toString() {
    return "Animal [name=" + name + ", weight=" + weight + ", color=" + color + ", type=" + type + ", age=" + age + ", lifetime=" + lifetime + "]";
  }
   
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package objectstream;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
 
import vo.Animal;
 
public class TestObjectStream {
  public static void main(String[] args) {
    try {
      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("d:/oos.dat")));
      Animal a1 = new Animal("tiger", 120, "red", "cat", 12, 20);
      Animal a2 = new Animal("eagle", 10, "gold", "bird", 6, 10);
      oos.writeObject(a1);
      oos.writeObject(a2);
      oos.flush();
      oos.close();
       
      ObjectInputStream ois = new ObjectInputStream(new FileInputStream("d:/oos.dat"));
      Animal ra1 = (Animal) ois.readObject();
      System.out.println(ra1.toString());
      Animal ra2 = (Animal) ois.readObject();
      System.out.println(ra2.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

輸出結(jié)果:

?
1
2
Animal [name=tiger, weight=120, color=red, type=cat, age=12, lifetime=20]
Animal [name=eagle, weight=10, color=gold, type=bird, age=6, lifetime=10]

如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,本站關(guān)于java開(kāi)發(fā)的文章還有很多,希望大家搜索查閱,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: av在线中文 | 国产精品一二三 | 免费观看一区二区三区 | 成人精品一区二区三区中文字幕 | 日韩资源 | 免费日韩一级片 | 91精品国产综合久久香蕉的用户体验 | 成年人精品视频 | 日韩极品在线 | 久久国产99| 亚洲天堂中文字幕在线观看 | 日韩黄网站 | 久久精品一 | 久久久精品国产 | 久久久国产精品免费观看 | 噜噜噜在线观看免费视频日本 | 永久看片 | 美女视频黄的免费 | 黄色成人影视 | 免费成人在线电影 | 在线日韩视频 | 一区二区精品视频 | 精品国产999 | 日韩免费av | h在线免费 | 毛片在线观看网站 | 久久美 | 欧美国产日韩一区二区三区 | 中文字幕视频在线 | 黄色毛片a | 亚洲骚片 | www国产亚洲精品久久网站 | 天堂久久久久久 | 亚洲欧美国产精品专区久久 | 久久香蕉综合 | 亚洲精品久久久一区二区三区 | 国产精品色一区二区三区 | 毛片在线网站 | 午夜寂寞少妇aaa片毛片 | 特黄特色大片在线观看视频网站 | 国产98色在线 | 日韩 |