CUSTOMER.JAVA:
import java.io.Serializable; public class Customer implements Serializable { private String name; private Integer number; private String address; public Customer() { super(); // TODO Auto-generated constructor stub } public Customer(String name, Integer number, String address) { super(); this.name = name; this.number = number; this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getNumber() { return number; } public void setNumber(Integer number) { this.number = number; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
MAIN.JAVA:
import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException, IOException{ Scanner s=new Scanner(System.in); System.out.println("Enter the Customer name"); String name=s.nextLine(); System.out.println("Enter the Customer number"); Integer number=s.nextInt(); System.out.println("Enter the Customer address"); s.nextLine(); String address=s.nextLine(); Customer cus=new Customer(name,number,address); try { FileOutputStream fileOut =new FileOutputStream("Serialize.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(cus); out.close(); fileOut.close(); } catch (IOException i) { i.printStackTrace(); } } }