Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package cw5;
  2. import java.io.Serializable;
  3. public class Book implements Serializable {
  4.  
  5. private static final long serialVersionUID = 1L;
  6. private String bookName;
  7. private String author;
  8.  
  9. public Book(String bookName, String author) {
  10. this.bookName = bookName;
  11. this.author = author;
  12. }
  13.  
  14. public String getBookName() {
  15. return bookName;
  16. }
  17.  
  18. public void setBookName(String bookName) {
  19. this.bookName = bookName;
  20. }
  21.  
  22. public String getAuthor() {
  23. return author;
  24. }
  25.  
  26. public void setAuthor(String author) {
  27. this.author = author;
  28. }
  29.  
  30. public String toString() {
  31.  
  32. return ("Book name: " + bookName + "\nAuthor name: " + author );
  33. }
  34.  
  35. }
  36.  
  37. =====================================================
  38.  
  39. package cw5;
  40. import java.io.FileInputStream;
  41. import java.io.IOException;
  42. import java.io.ObjectInputStream;
  43.  
  44. public class BinaryInputFile {
  45.  
  46. public static void main(String[] args) throws IOException {
  47. FileInputStream file = new FileInputStream("test.bin");
  48. ObjectInputStream in = new ObjectInputStream(file);
  49. for(int i = 0; i < 10; i++)
  50. System.out.println(in.readInt());
  51. in.close();
  52. System.out.println("Done");
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement