private void generatePlayListFile(Song[] songs)throws Exception{
ServletRequest request = ServletActionContext.getRequest();
localAddr = "http://" + request.getLocalAddr() + ":8080" + "/popmusic";
songListFileName += ".m3u";
String songListLocation = request.getRealPath("/upload") + "/" + songListFileName;
PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(songListLocation))); for(int i = 0; i < songIds.length; i++){
String tempLocation = songs[i].getLocation();
String songFileName = tempLocation.substring(tempLocation.lastIndexOf("/") + 1);
out.println(songFileName);
}
out.close();
}

解决方案 »

  1.   

    上面代码不全,少一些,重新附上。private Long[] songIds;
    private String songListFileName="";
    private SongManageService songManageService;
    private String localAddr;
    private Map<Song, Set<Singer>> songSingerMap = new HashMap<Song, Set<Singer>>();
    private Logger logger = Logger.getLogger(PlaySongAction.class);

    public String execute()throws Exception{

      Song[] songs = new Song[songIds.length];
    for(int i = 0; i < songIds.length; i++){
    songListFileName += songIds[i] + "_";
    songs[i] = songManageService.getSongById(songIds[i]);
    }
    generatePlayListFile(songs);

    return SUCCESS;
    }private void generatePlayListFile(Song[] songs)throws Exception{
    ServletRequest request = ServletActionContext.getRequest();
    localAddr = "http://" + request.getLocalAddr() + ":8080" + "/popmusic";
    songListFileName += ".m3u";
    String songListLocation = request.getRealPath("/upload") + "/" + songListFileName;
    PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(songListLocation))); for(int i = 0; i < songIds.length; i++){
    String tempLocation = songs[i].getLocation();
    String songFileName = tempLocation.substring(tempLocation.lastIndexOf("/") + 1);
    out.println(songFileName);
    }
    out.close();
    }