我现在用的是weblogic服务器,有如下流程:
1,删除生成的Excle文件(因为下次还是往相同的文件夹中输出)
2,得到一list,根据list中的数据,输出Excel文件到某一文件夹
3,打包文件,发到给客户端 if(!delAllFile(outpath)){②
throw new Exception();
}
OutputStream out = null;
try {
.......
for(int m = 0;m<3;m++){
.......
String strOutFilePath = outpath + "/fu"+ m +".xls";
out = new FileOutputStream(strOutFilePath);
.......①
wb.write(out);
out.flush();
out.close();
out = null;
} }catch(Exception e) {
throw ee;
} finally { }
现在的问题是,如果①的位置上的程序如果出了问题,抛了异常的话,out就没有执行flush()和close()
所以下次执行的时候,②位置的删除文件操作就不能删除上次执行是时out指定的文件,就无法删除。
而在,catch和finally中无法执行out.flush()和out.close(),因为out还没有实例化,只能执行out=null
但是没有用。
请各位高手,指点一下,先谢谢了
1,删除生成的Excle文件(因为下次还是往相同的文件夹中输出)
2,得到一list,根据list中的数据,输出Excel文件到某一文件夹
3,打包文件,发到给客户端 if(!delAllFile(outpath)){②
throw new Exception();
}
OutputStream out = null;
try {
.......
for(int m = 0;m<3;m++){
.......
String strOutFilePath = outpath + "/fu"+ m +".xls";
out = new FileOutputStream(strOutFilePath);
.......①
wb.write(out);
out.flush();
out.close();
out = null;
} }catch(Exception e) {
throw ee;
} finally { }
现在的问题是,如果①的位置上的程序如果出了问题,抛了异常的话,out就没有执行flush()和close()
所以下次执行的时候,②位置的删除文件操作就不能删除上次执行是时out指定的文件,就无法删除。
而在,catch和finally中无法执行out.flush()和out.close(),因为out还没有实例化,只能执行out=null
但是没有用。
请各位高手,指点一下,先谢谢了
.......
for(int m = 0;m<3;m++){
.......
String strOutFilePath = outpath + "/fu"+ m +".xls";
OutputStream out = new FileOutputStream(strOutFilePath);
try {
......①
wb.write(out);
out.flush();
} catch(Exception ee) {
throw ee;
} finally {
try { if (out != null) out.close(); } catch (IOException ioe) { }
}
}
...
if( null != out ){
try(out.flush();)catch(Exception e){}
try(out.close();)catch(Exception e){}
}}
把上面out.flush();out.close(); 加到
finally 中
就可以
因为我没有把out.colse放到try{}catch{}中。