新手编程,写个音乐网站,知道ftp服务器的地址、上传用户和密码,希望通过上传MP3到ftp服务器获得MP3歌曲链接,并通过链接来播放和下载音乐,但不知道怎么获得链接,一直无从下手,求高手支援,或者传授更好好的播放和下载MP3的方法

解决方案 »

  1.   

    fileUpload 不行吗  你可以先判断下后缀是不是.mp3文件
      

  2.   


    private File upload;// 封装上传文件
    private String uploadFileName;// 设置上传文件的文件名
    private String uploadContentType;// 上传文件的类型
    public File getUpload() {
                return upload;
    }public void setUpload(File upload) {
            this.upload = upload;
    }public String getUploadFileName() {
            return uploadFileName;
    }public void setUploadFileName(String uploadFileName) {
            this.uploadFileName = uploadFileName;
    }public String getUploadContentType() {
            return uploadContentType;
    }public void setUploadContentType(String uploadContentType) {
            this.uploadContentType = uploadContentType;
    }
    /**
             * xml文件上传
             *
             * @return
             * @throws Exception
             */
            public String xmlUpload() {
                    if (this.getUpload() == null) {
                            this.addActionError("不允许上传空文件,请您重新上传!");
                            return "Error";
                    }
                    FileOutputStream fos = null;
                    String basePathfile = 你要上传的文件路径 + getUploadFileName();
                    try {
                            fos = new FileOutputStream(basePathfile);
                    } catch (FileNotFoundException e) {
                            e.printStackTrace();
                    }
                    FileInputStream fis = null;
                    try {
                            fis = new FileInputStream(getUpload());
                    } catch (FileNotFoundException e) {
                            e.printStackTrace();
                    }
                    byte[] buffer = new byte[1024];
                    int len = 0;
                    try {
                            while ((len = fis.read(buffer)) > 0) {
                                    fos.write(buffer, 0, len);
                            }
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
                    try {
                            fos.flush();
                            fos.close();
                            fis.close();
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
                    System.out.println("导入完成");
                    return SUCCESS;
            }