| finally的神秘问题 |
| [ 来源:ITWENKU 时间:2006-9-7 16:33:42 | 浏览:183人次
] |
| |
byte abc[]=new byte[80]; FileOutputStream oFile; try{ oFile=new FileOutputStream("d:\\temp.txt"); oFile.write(abc); }catch(IOException e1){} finally{ oFile.close(); }
报错:variable oFile might not have been initialized at line 63, column 7 咋整,同志们!
局部变量必须初始化; FileOutputStream oFile=null;
public static void main(String[] args) { // TODO Auto-generated method stub byte abc[]=new byte[80]; FileOutputStream oFile=null; try{ oFile=new FileOutputStream("d:\\temp.txt"); oFile.write(abc); oFile.flush(); }catch(IOException e1){} finally{ try{ oFile.close(); }catch(IOException e1){} }
}
同意楼上想法,必须初始化.
static void f5 () throws IOException { byte abc[]=new byte[80]; FileOutputStream oFile =new FileOutputStream("d:\\temp.txt"); oFile.write(abc); oFile.close();
楼主会不会结帖??打击回帖积极性....
|
|
 |
最新更新 |
|