try {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd_HH_mm");
String filename = sf.format(new Date()).toString() + "_Export.txt";
//可直接下載檔案
String filepath = filename;
response.reset();
response.setContentType("application/octet-stream");
String fileName = URLDecoder.decode(filepath, "utf-8");
java.net.URLEncoder.encode(fileName, "utf-8");
//response.addHeader("Content-Disposition", "attachment;" + "filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
String str = "";
str += "aaaa\r\n";
byte[] byt = str.getBytes();
os.write(byt);
} catch (Exception e) {
e.printStackTrace(System.err);
} finally {
os.flush();
os.close();
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
}
return null;
}
可以參考:http://www.xuehuile.com/blog/56ab65630b754301b4a7ece3edbca6c9.html
沒有留言:
張貼留言