[問題] 程式執行後無法刪除檔案

看板java作者 (No One Knows)時間14年前 (2012/01/17 14:06), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
最近在寫一個搬移檔案的程式的時候 發生了無法刪除原始檔的問題 不知道是為什麼 程式碼也沒錯 但在fi.delete(); 這段跑出來的結果卻是false 我也有把FileReader、FileWriter給close掉了 結果還是不會刪,請問造成的原因會是什麼啊@@ 謝謝 ---------------------------以下為程式碼--------------------------------- public void Barcode_Dir(String Dir) throws IOException { File fi = new File("oldpath"); File finew = new File("newpath"); if (fi.exists()){ WriteOfBarcode(fi.getPath()); FileReader in = new FileReader(fi); FileWriter out = new FileWriter(finew); int c; while((c = in.read()) != -1) out.write(c); in.close(); out.close(); fi.delete(); } else{ util_log.OutputLog("找不到檔案"); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.70.208.96 ※ 編輯: fowx 來自: 203.70.208.96 (01/17 14:06)

01/17 14:38, , 1F
WriteOfBarcode()怎不po出來?
01/17 14:38, 1F

01/17 14:45, , 2F
因為那段副程式很長...而且裡面也只是把讀到得資料寫進資料庫
01/17 14:45, 2F

01/17 18:01, , 3F
WriteOfBarcode()這段刪了就正常了,所以問題應該在
01/17 18:01, 3F

01/18 08:39, , 4F
謝謝…問題真的在裡面
01/18 08:39, 4F
文章代碼(AID): #1F5G_9yg (java)