import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
public void exPortTxt(HttpServletResponse response,String txt)
{
response.setContentType("application/txt");
response.setHeader("Content-disposition", "attachment;filename=mytxt.txt");
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(response.getOutputStream());
bos.write(txt.getBytes());
} catch (IOException e) {
try {
throw e;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} finally {
if (bos != null)
try {
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
直接把内容拼成字符串,然后传入,直接写到TXT里面;
PrintWriter out = response.getWriter();//必须注释掉, 不然就不能导出了,和导出流冲突