Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the program below I created one student record.for Jon Doe. How can I create more student records? Could the answer be typewritten not handwritten

In the program below I created one student record.for Jon Doe. How can I create more student records? Could the answer be typewritten not handwritten please.

import java.io.*; import java.util.*;

import serialization.Student;

public class Student implements Serializable { // Setting the serialVersionUID private static final long serialVersionUID = 1L;

public static final String fileName = null;

// The data that belongs to the class Student private String studentID, firstName, lastName, dob, course, enrollmentDate; // constructor for the class Student public Student(String studentID, String firstName, String lastName, String dob, String course, String enrollmentDate) { //this.studentID refers to object studentID in the current class this.studentID = studentID; this.firstName = firstName; this.lastName = lastName; this.dob = dob; this.course = course; this.enrollmentDate = enrollmentDate; } // TODO Auto-generated constructor stub public Student() { }// Creates a String representation of an object public String toStriing() { //object passed to function return(studentID +" "+ firstName +" "+ lastName +" "+ dob +" "+ course +" "+ enrollmentDate); } public static class JavaSeriialization{

public static void main(String[] args) { // An object of the type Student initialized Student student = new Student("P101"," Jon","Doe","11/11/68", "APC", "12/12/19"); // A file set for writing down the serialized/deserialized dada String fileneme = ("E:\\SerialFile.txt"); // Serialization try { // FileOutputStream connected to the file to write content FileOutputStream file = new FileOutputStream("E:\\Deserialize.txt"); // ObjectOutputStream connected to the FileOutputStream to write the Object to the file ObjectOutputStream obj = new ObjectOutputStream(file); // writeObject(object) writes the serialized data to the file obj.writeObject(student); System.out.println("Serialization completed"); obj.close(); } catch(IOException e) { e.printStackTrace(); }// deserializtion student = null; try { // FileInputStream is connected to the file to read content FileInputStream file = new FileInputStream("E:\\Deserialize1.txt"); // ObjectInputStream connected to the FileInputStream to read the serialized data from the file ObjectInputStream obj = new ObjectInputStream(file); // readOject() reads the serialized data and deserilizes it to the object obj1 student = (Student)obj.readObject(); obj.close(); file.close(); // Printing the deserialized object System.out.println(" Deserialized objects data "); System.out.println(student); // Writing the deserialized data to the file FileOutputStream fs = new FileOutputStream("E:\\Deserialize.txt"); String stu = student.toStriing(); byte[] bytesArray = stu.getBytes(); fs.write(bytesArray); fs.close(); } catch(IOException e) { e.printStackTrace(); } catch(ClassNotFoundException e) { e.printStackTrace(); } }

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Y dy + m2 y = 21 (14) 1+t2 2. Solve dy + ; y(1) = 1 Tental 3 merk

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago