[問題] 關於IO內close的問題

看板java作者 (住在巴別塔的男孩)時間18年前 (2008/01/07 22:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
當file丟出exception後file會不會自動執行close()啊? 本來想寫以下的code: RandomAccessFile test = null; try { test = new RandomAccessFile("test.dat", "r"); ... } catch (FileNotFoundException e) { ... } (一堆catch...) finally { test.close(); } 可是compile時compiler說finally裡面的test要放在try裡面, 這樣不就一直try try try try ... 無窮回圈 = = 我是擔心丟出Exception之後file不會自動執行close()才這樣寫的啦, 不然test.close()寫在try最後面就好了, 還是我多慮了~"~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.102.28 ※ 編輯: ericsys3152 來自: 140.116.102.28 (01/07 22:30)
文章代碼(AID): #17WZOLgq (java)
文章代碼(AID): #17WZOLgq (java)