tags:

views:

72

answers:

4

Hello.

I am making my own crude MP3 player, and I now have a JList with which I have populated a number 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.

A: 

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

Chandru
A: 

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).

Scott
+1  A: 

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?

Tom Brito
A: 

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

      }

}
rgksugan