向用户显示字符串列表。程序将要求用户从文本文件(在本例中为.m3u文件)中输入与要删除的字符串对应的编号。如何永久保存用户对文本文件所做的更改?
我的代码:
else if (userSelectedCode == OptionID.OPTION_DELETE_MUSIC_TRACK) {
String filename = "user needs to select this.m3u";
//model.DeleteFirstPlaylist(filename);
List<M3UTrack> trackList = model.getFirstPlaylist().getTracks();
for (int i = 0; i < trackList.size(); i++)
{
System.out.println((i+1) + ": " + trackList.get(i).getTrackFilename());
}
Scanner in = new Scanner(System.in);
System.out.println("Input number of the music track to delete");
int trackNum = in.nextInt();
{
model.getFirstPlaylist().deleteTrack(trackList.get(trackNum-1));
}
我怀疑它涉及使用FileWriter?这会是一个开始吗?:
FileWriter writer = new FileWriter("C:/Data/Projects/MusicOrganizer/music.m3u");
writer.flush();
writer.close();