aboutsummaryrefslogtreecommitdiffstats
path: root/Song.java
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2020-12-11 09:12:05 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2020-12-11 09:12:05 +0100
commit532cd1e395a637a5e507bc3687a4a64e50e55b30 (patch)
treef15d9b5a14e1129aa9b9629d842dcf8f99745d5d /Song.java
parentec126de053cd1343e0c5778a56ea58045d0e3170 (diff)
downloadjMusicHub-532cd1e395a637a5e507bc3687a4a64e50e55b30.tar.gz
jMusicHub-532cd1e395a637a5e507bc3687a4a64e50e55b30.tar.bz2
jMusicHub-532cd1e395a637a5e507bc3687a4a64e50e55b30.zip
adding Serialization interface and methods
Diffstat (limited to '')
-rw-r--r--Song.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/Song.java b/Song.java
index c4d1fc3..ecbb1eb 100644
--- a/Song.java
+++ b/Song.java
@@ -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");
+ }
+ }
+
}