浏览 7192 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-11-17
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; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-12-26
读写文件的时候不是已经处理了吗,不是使用一个循环就可以判断文件已经读到之后的位置了吗,等于-1的时候说明已经读到文章最后的位置了
|
|
返回顶楼 | |
发表时间:2012-05-06
同求啊,楼主现在的解决方法是?
|
|
返回顶楼 | |