Source Code : Store objects in file
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Store objects in file
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Main {
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("books.dat");
ObjectOutputStream oos = new ObjectOutputStream(fos);
Book book = new Book("1", "Java", "A");
oos.writeObject(book);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream("books.dat");
ObjectInputStream ois = new ObjectInputStream(fis);
book = (Book) ois.readObject();
System.out.println(book.toString());
ois.close();
}
}
class Book implements Serializable {
private String isbn;
private String title;
private String author;
public Book(String isbn, String title, String author) {
this.isbn = isbn;
this.title = title;
this.author = author;
}
public String toString() {
return "[Book: " + isbn + ", " + title + ", " + author + "]";
}
}
Thank with us