MappedByteBuffer 之檔案刪除問題

2021-08-30 12:40:25 字數 1048 閱讀 6683

看如下測試**:

file testfile;

/*** 建立測試檔案

* @throws urisyntaxexception

* @throws ioexception

*/@before public void createfile() throws urisyntaxexception, ioexception

fileoutputstream fos = new fileoutputstream(testfile);

fos.close(); }

/*** @throws ioexception

*/@test public void testdeletefile() throws ioexception

/*** @param file

* @return

* @throws ioexception

*/fileinputstream in = new fileinputstream(file);

filechannel ch = in.getchannel();

ch.close();

in.close();

return buffer; }}

junit執行,結果斷言失敗,檔案沒刪除成功。

解決方法是加上如下**:

/**

* @param buffer

*/if (buffer == null)

accesscontroller.doprivileged(new privilegedaction()

}} catch (exception e)

return null;

}}

然後將testdeletefile() 作如下修改:

/**

* @throws ioexception

*/@test public void testdeletefile() throws ioexception

再執行junit,成功!

Android之刪除檔案

android之刪除檔案。但是,如果刪除的是的話,此方法刪除的只是自定義資料夾下的檔案,相簿裡的並不能刪除。刪除檔案,可以是檔案或資料夾 param delfile 要刪除的資料夾或檔名 return 刪除成功返回true,否則返回false public static boolean delete...

adb Read only及刪除資料夾相關問題

解決方案 首先adb remount adb shell後,將system 和lib資料夾的讀寫模式改掉,chmod 777 system 再試一次就可以了 刪除檔案相關操作 tools adb remount 重新磁碟掛載 tools adb shell 進入shell su 超級使用者 cd s...

Git之刪除 恢復檔案

git rm,把本地檔案給刪掉 把本地原庫刪除 刪除 想要刪除的檔案 git status 檢視修改,確保已經刪除 git commit a 在本地庫儲存修改版本 git push original master 更新github 網路原庫。2 如果乙個檔案被刪除了,可以使用切換版本號進行恢復。恢復...