• 对象流demo1----


    对象流demo1:
    
    package com.etc.test;
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.NotSerializableException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    class Customer implements Serializable
    {
    	private String name,ID;
    	private String password;
    	private float salary;
    	public String getName() {
    		return name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	public String getID() {
    		return ID;
    	}
    	public void setID(String iD) {
    		ID = iD;
    	}
    	public String getPassword() {
    		return password;
    	}
    	public void setPassword(String password) {
    		this.password = password;
    	}
    	public float getSalary() {
    		return salary;
    	}
    	public void setSalary(float salary) {
    		this.salary = salary;
    	}
    	public Customer(String name, String iD, String password, float salary) {
    		super();
    		this.name = name;
    		ID = iD;
    		this.password = password;
    		this.salary = salary;
    	}
    	
    }
    public class ObjectDemo {
    public static void main(String[] args) {
    	try 
    	{
    		ObjectOutputStream objectOut=new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("object.bin")));
    		Customer cus=new Customer("wen", "2", "rytf", 2300);
    		objectOut.writeObject(cus);
    		objectOut.close();
    		ObjectInputStream objectIn=new ObjectInputStream(new BufferedInputStream(new FileInputStream("object.bin")));
    		cus=(Customer) objectIn.readObject();
    		System.out.println("name:"+cus.getName());
    		System.out.println("id:"+cus.getID());
    		System.out.println("password:"+cus.getPassword());
    		System.out.println("salary:"+cus.getSalary());
    	
    	
    	}
    	catch(NotSerializableException e)
    	{
    		System.out.println(e.getMessage());
    	}
    	catch (ClassNotFoundException e) {
    		System.out.println(e.getMessage());
    		
    	} catch (IOException e) {
    		
    		System.out.println(e.getMessage());
    	}
    }
    }
    ========================================================================
    

      

  • 相关阅读:
    Vue2020
    Vue2020
    Vue v-model双向数据绑定 的实现
    TCP 粘包
    黑幕模板
    STL总结与例子
    中缀表达式转后缀表达式
    php 转换数组里的时间戳
    gorm踩过的坑
    WxJava使用lettuce客户端的redis实现微信access_token等接口重复利用
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6292563.html
Copyright © 2020-2023  润新知