导出word2

public void download(){

String fileName = request.getParameter("fileid");

try {

request.setCharacterEncoding("utf-8");

fileName = new String(fileName.getBytes("iso-8859-1"), "utf-8");

//获取文件路径

String filePath = "E:\\THSPlatform\\projects\\serviceGuide-archetype\\src\\main\\webapp\\WEB-INF\\conf\\res\\servicecontent\\baseword\\"+fileName;

filePath = filePath == null ? "" : filePath;

              //设置向浏览器端传送的文件格式

                      response.setContentType("application/x-download");

                      fileName = URLEncoder.encode(fileName, "UTF-8");

response.addHeader("Content-Disposition", "attachment;filename="

+ fileName);

FileInputStream fis = null;

OutputStream os = null;

try {

os = response.getOutputStream();

fis = new FileInputStream(filePath);

byte[] b = new byte[1024 * 10];

int i = 0;

while ((i = fis.read(b)) > 0) {

os.write(b, 0, i);

}

os.flush();

os.close();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (fis != null) {

try {

fis.close();

} catch (IOException e) {

e.printStackTrace();

}

}

if (os != null) {

try {

os.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}

}

你可能感兴趣的:(导出word2)