将MP3播放列表保存到文件

时间:2010-02-24 01:56:45

标签: java io jlist

我正在制作自己的原始MP3播放器,现在我有一个JList,我已经用MP3对象的形式填充了许多文件(使用DefaultListModel在框架上显示)。

我现在希望有机会将此JList保存到磁盘上的文件中。我该怎么做呢?

我是编程和Java的新手,所以非常感谢帮助。

4 个答案:

答案 0 :(得分:1)

最简单的方法是使用Serialization

更一致(我认为这个词)是使用java io使用简单的 for 循环逐项将列表写入文件。

有帮助吗?

答案 1 :(得分:0)

您可以使用M3UPLS格式从JList中的项目创建播放列表文件。

答案 2 :(得分:0)

您是否尝试将其另存为播放列表文件,以便通过媒体播放器打开?

如果您只是想将其保存为文本文件,请打开一个简单的输出流并将其命名为“playlist.txt”,然后循环遍历JList的每条记录并写下您需要的信息,然后按新行(\ n)。

答案 3 :(得分:0)

如果要以Jlist对象本身的形式检索数据,最好使用对象序列化。

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

否则,如果您希望以文本格式检索数据,请按照其他人提到的步骤进行操作。

可能是tis代码会帮助

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

      }

}