Saving an MP3 playlist to a file

I make my own raw MP3 player, and now I have a JList with which I filled in several files as MP3 objects (displayed on the frame using DefaultListModel).

Now I would like to have oppurtunity to save this JList to a file on disk. How can i do this?

I am very new to programming and Java, so they help us a lot.

+4
source share
4 answers

if you want to get the data back as a Jlist object itself, it is better to use object serialization.

ObjectOutput ObjOut = new ObjectOutputStream (new FileOutputStream (f));

else, if you want the data to be extracted in text format, follow the instructions given by others.

maybe tis code will help

public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String filename = "playlist.dat"; File f = new File(filename); try{ ObjectOutput ObjOut = new ObjectOutputStream(new FileOutputStream(f)); ObjOut.writeObject(//ur JList object); ObjOut.close(); System.out.println("Serializing an Object Creation completed successfully."); } catch(IOException e){ System.out.println(e.getMessage()); } } 
0
source

The easiest way is to use Serialization .

More sequential (I think this word) uses java io to write a list to a file, by elements, using a simple loop for .

Does it help?

+1
source

You can use M3U or PLS to create playlist files from items in your JList.

0
source

Are you trying to save this as a playlist file that should be opened by the media player?

If you are just trying to save this as a text file, open a simple output stream and name it "playlist.txt" and just skip each JList entry and write the necessary information, followed by a new line (\ n).

0
source

Source: https://habr.com/ru/post/1302190/


All Articles