论坛首页 Java企业应用论坛

Struts2 文件下载之后,如何判断文件已经下载完成

浏览 7192 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-11-17  
这个是下载的CODE,如何得知文件已经下载完成,我想在前台弹出一个提示框,让用户确定文件已经下载完成
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;


import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;



/**
 * @author wangpeng
 * 后台Action类 - Excel导出
 */
@ParentPackage("admin")
@Results({@Result(name="downloadResume" ,type="stream",
		params={"contentType","application/x-xls",
		"contentDisposition","attachment;filename=\"${downloadChineseFileName}\"",
		"inputName","downloadResume","bufferSize","4096"})})
public class DownLoadAction extends BaseAdminAction{
	
	private static final long serialVersionUID = -2949204680074334045L;

	private String fileName; //文件名
	
	private String contentType; //文件类型
	
	public String downloadResume(){
		return "downloadResume";
	}
	
	@SuppressWarnings("unchecked")
	public InputStream getDownloadResume() throws Exception{
		File f = new File(fileName);
		InputStream is = new FileInputStream(f);
		return is;
	}
	//如果下载文件名为中文,进行字符编码转换   
    public String getDownloadChineseFileName() {   
		String downFileName = fileName.substring(fileName.indexOf("@")+1,fileName.length());
        String downloadChineseFileName = downFileName;   
        try {   
            downloadChineseFileName = new String(downloadChineseFileName.getBytes(), "ISO8859-1");   
        } catch (UnsupportedEncodingException e) {   
            e.printStackTrace();   
        }   
        return downloadChineseFileName;   
    }  
    
	public String getContentType() {
		return contentType;
	}
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
   发表时间:2011-12-26  
读写文件的时候不是已经处理了吗,不是使用一个循环就可以判断文件已经读到之后的位置了吗,等于-1的时候说明已经读到文章最后的位置了
0 请登录后投票
   发表时间:2012-05-06  
同求啊,楼主现在的解决方法是?
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics