How can I save a song playlist in JFX?

0 votes
asked by (340 points)
retagged by

I want to make a media player in Java and I want to save my song playlist like Windows Media Player saves current playlist. And whenever I open the Java player, I should load the playlist from a file. I don't know how to do this. Can anyone help me with this problem?

1 Answer

0 votes
No avatar answered by (79.9k points)
edited by

You can write the playlist into a file but if you want to read the file after, you should use the playlist as an object and serialize it. The writing procedure should look something like this:

FileOutputStream f = new FileOutputStream("tmp");
ObjectOutput s = new ObjectOutputStream(f);
s.writeObject("Today");
s.writeObject(new Date());
s.flush();

And the reading procedure should look something like this:

FileInputStream in = new FileInputStream("tmp");
ObjectInputStream s = new ObjectInputStream(in);
String today = (String)s.readObject();
Date date = (Date)s.readObject();

- Source Oracle docs

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...