输出txt文件

输出txt文件

response.setContentType("text/plain;charset=UTF-8");
response.addHeader("Content-Disposition","attachment;filename=error.txt");
//为什么这个文件名不能是中文?
BufferedOutputStream buff = null;
StringBuffer write = new StringBuffer();
ServletOutputStream outStr = null;
try {
	outStr = response.getOutputStream();
	buff = new BufferedOutputStream(outStr);
	write.append("测试输出");
	buff.write(write.toString().getBytes("utf-8"));
	buff.flush();
}catch(Exception e) {
	e.printStackTrace();
}finally {
	buff.close();
	outStr.close();
}

你可能感兴趣的:(txt)