diff options
Diffstat (limited to 'Song.java')
-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"); + } + } + } |