struts2 action中读文件流至页面显示。
public void showSwf() {
HttpServletResponse response = ServletActionContext.getResponse();
FileInputStream in = null;
ServletOutputStream output = null;
try {
File file = new File("E:\\Paper.swf");
in = new FileInputStream(file);
output = response.getOutputStream();
byte[] b = new byte[4096];
int n;
while ((n = in.read(b)) != -1) {
output.write(b, 0, n);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
in.close();
output.flush();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}