站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2SE 专题finally的神秘问题

finally的神秘问题

摘要: finally的神秘问题


byte abc[]=new byte[80];
FileOutputStream oFile;
try{
oFile=new FileOutputStream(-#34;d://temp.txt-#34;);
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(-#34;d://temp.txt-#34;);
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(-#34;d://temp.txt-#34;);
oFile.write(abc);
oFile.close();


楼主会不会结帖??打击回帖积极性....


↑返回目录
前一篇: 用http post上传图片的问题
后一篇: 如果获得文件的长度?