diff options
| author | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-11 09:12:05 +0100 |
|---|---|---|
| committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2020-12-11 09:12:05 +0100 |
| commit | 532cd1e395a637a5e507bc3687a4a64e50e55b30 (patch) | |
| tree | f15d9b5a14e1129aa9b9629d842dcf8f99745d5d /Song.java | |
| parent | ec126de053cd1343e0c5778a56ea58045d0e3170 (diff) | |
| download | jMusicHub-532cd1e395a637a5e507bc3687a4a64e50e55b30.tar.gz jMusicHub-532cd1e395a637a5e507bc3687a4a64e50e55b30.tar.bz2 jMusicHub-532cd1e395a637a5e507bc3687a4a64e50e55b30.zip | |
adding Serialization interface and methods
Diffstat (limited to '')
| -rw-r--r-- | Song.java | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -1,4 +1,4 @@ -public class Song extends MusicalElement { +public class Song extends MusicalElement{ private String artist, genre; public Song(String title, int duration, String content, String artist, Genre genre) { super(title, duration, content); @@ -15,5 +15,28 @@ public class Song extends MusicalElement { return getTitle()+";"+getDuration()+";"+getContent()+";"+artist+";"+genre; } + public void save(){ + try + { + //Saving of object in a file + FileOutputStream file = new FileOutputStream(songs.csv); + ObjectOutputStream out = new ObjectOutputStream(file); + + // Method for serialization of object + out.writeObject(this); + + out.close(); + file.close(); + + System.out.println("Object has been serialized"); + + } + + catch(IOException ex) + { + System.out.println("IOException is caught"); + } + } + } |
