亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java中刪除一個文件夾下的所有文件

java中刪除一個文件夾下的所有文件

qq_Dreamy_舊城_0 2017-12-04 16:26:34
/** * ?刪除文件夾里面的所有文件 * ?@param ?path ?String ?文件夾路徑 ?如 ?c:/fqf */public static void ?delAllFile(String ?path) ?{ ? ?File ?file ?= ?new ?File(path); ? ?if ?(!file.exists()) ?{ ? ? ? ?return; ? ?} ? ?if ?(!file.isDirectory()) ?{ ? ? ? ?return; ? ?} ? ?String[] ?tempList ?= ?file.list(); ? ?File ?temp ?= ?null; ? ?for ?(int ?i ?= ?0; ?i ?< ?tempList.length; ?i++) ?{ ? ? ? ?if ?(path.endsWith(File.separator)) ?{ ? ? ? ? ? ?temp ?= ?new ?File(path ?+ ?tempList[i]); ? ? ? ?} ? ? ? ?else ?{ ? ? ? ? ? ?temp ?= ?new ?File(path ?+ ?File.separator ?+ ?tempList[i]); ? ? ? ?} ? ? ? ?if ?(temp.isFile()) ?{ ? ? ? ? ? ?temp.delete(); ? ? ? ?} ? ? ? ?if ?(temp.isDirectory()) ?{ ? ? ? ? ? ?//先刪除文件夾里面的文件 ? ? ? ? ? ?delAllFile(path+"/"+ ?tempList[i]); ? ? ? ? ? ?/*//再刪除空文件夾 ? ? ? ? ? ?delFolder(path+"/"+ ?tempList[i]);*/ ? ? ? ?} ? ?}}我這邊找了一個,寫著說是能刪除多個文件,但我運行了只能刪除一個,會的麻煩教教我,謝謝啦
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 1625 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號