`
michaeltangbin
  • 浏览: 268907 次
  • 性别: Icon_minigender_1
  • 来自: 黑龙江省
社区版块
存档分类
最新评论

dwr实现文件的下载--已经解决中文文件名乱码问题

    博客分类:
  • java
阅读更多


package com.wabacusdemo.util;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

import org.directwebremoting.io.FileTransfer;

public class DownLoadFile {
	public FileTransfer downloadPdfFile(String contents) throws Exception {
	    if (contents == null || contents.length() == 0) {
	        contents = "[BLANK]";
	    }
	    BufferedInputStream in = new BufferedInputStream(new FileInputStream("c:/Aix 脆弱性库.xls"));
	    ByteArrayOutputStream out = new ByteArrayOutputStream();
	    byte[] temp = new byte[1024];
	  int size = 0;  
	  while ((size = in.read(temp)) != -1)
	  {
		out.write(temp, 0, size);
	  }
	  String  filename ="测试.doc";
	  return new FileTransfer(new String( filename.getBytes("GBK"),"iso8859-1" ), "application/doc", out.toByteArray());
	}
}
 
function downloadPdfFile() {
 // var pdftext = dwr.util.getValue('pdftext');

	DownLoadFile.downloadPdfFile("ddd", function(data) {
    dwr.engine.openInDownload(data);
  });
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics