开发者

Saving MP3 playlist to file

I am making my own crude MP3 player, and I now have a JList with which I have populated a nu开发者_如何学JAVAmber of files in the form of MP3 objects (displayed on frame using DefaultListModel).

I would now like to have the oppurtunity to save this JList to a file on disk. How would I go about doing this?

I'm very new with programming and Java, so help is greatly appreciated.


The simplest way is by using Serialization.

The more consistent (i think this is the word) is using the java io to write the list to the file, item by item, using a simple for loop.

Does it help?


if you want to retrieve the data back in the form of the Jlist object itself you better use object serialization.

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

else if you want the data to be retrieved in the text format follow the steps mentioned by others.

might be 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());

      }

}


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


Are you trying to save this as a playlist file, to be opened with a media player?

If you're just trying to save this as like a text file, open a simple output stream and call it 'playlist.txt', and just loop through each record of the JList and write the info you need followed by a new line (\n).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜