本文实例讲述了Java导出txt文件的方法。分享给大家供大家参考。具体如下:
例子一
/**
* export导出文件
*/
@RequestMapping(value="/grab/export/csv",method={RequestMethod.GET})
public void exportCsv(HttpServletRequest request,HttpServletResponse response){
String userId = ServletRequestUtils.getStringParameter(request, "userId", "test");
ModelAndView mav=new ModelAndView();
SqlVideoList sqlVideoList =new SqlVideoList();
List list = new ArrayList();
try {
list = sqlVideoList.selectSuccessDate(userId);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//导出txt文件
response.setContentType("text/plain");
String fileName="videolist";
try {
fileName = URLEncoder.encod