一个很简明的小例子:
File dir=new File(“路径”);
if(!dir.exists())
dir.mkdir();
一个简明的小例子:
String filedisplay = session.getAttribute("username")+"的报表.xls";
filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
java.io.OutputStream outp = null;
java.io.FileInputStream in = null;
try {
outp = response.getOutputStream();
in = new FileInputStream(file);
byte[] b = new byte[1024];
int i = 0;
while((i = in.read(b)) > 0) {
outp.write(b, 0, i);
}
outp.flush();
out.clear();
out = pageContext.pushBody();
}
catch(Exception e) {
System.out.println("Error!");
e.printStackTrace();
}
finally {
if(in != null) {
in.close();
in = null;
}
if(outp != null){
outp.close();
outp = null;
}
}