diff options
author | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-11 10:06:34 +0100 |
---|---|---|
committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-11 10:06:34 +0100 |
commit | 67db3838608308576ef28c0259dc0584673d27a8 (patch) | |
tree | 611f0da23402dff667712e271f6ef9447354f4cd /jMusicHub.java | |
parent | 532cd1e395a637a5e507bc3687a4a64e50e55b30 (diff) |
Getting serialization working with a song
Diffstat (limited to 'jMusicHub.java')
-rw-r--r-- | jMusicHub.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/jMusicHub.java b/jMusicHub.java index 2cbedc3..26fe9b6 100644 --- a/jMusicHub.java +++ b/jMusicHub.java @@ -1,4 +1,5 @@ import java.util.*; +import java.io.*; /** <h1>jMusicHub</h1> * @@ -120,10 +121,33 @@ public class jMusicHub { break; case "s": for (Song s: songs){ - s.save(); - } + String filename = "songs.csv"; + + // Serialization + try { + + // Saving of object in a file + FileOutputStream file = new FileOutputStream + (filename); + ObjectOutputStream out = new ObjectOutputStream + (file); + + // Method for serialization of object + out.writeObject(s); + + out.close(); + file.close(); + System.out.println("Object has been serialized\n" + + "Data before Deserialization."); + System.out.println(s); + } + catch (IOException ex) { + System.out.println("IOException is caught"); + } + } break; + default : System.out.println("Unknown command. Type h for help."); |