天天看點

調試模式 file.exits判斷目錄異常

代碼如下:

public class testfile {

    public native RenderCar();

    public native RenderSky();

    public boolean testPathExit()

    {

        String str = Environment.getExternalStorageDirectory().getPath();

        str = str + "/Android/data/test/";

        String str1 = "/storage/sdcard0/Android/data/test/";

        File file = new File(str);

        if (file.exists())

        {

            return true;

        }

        return false;

    }

    public String getDataPath()

        if (file.exists()) {

            return str;

        return str1;

}

說明:該類編寫了一些native函數,調用Jni實際的函數實作,在調試模式下getDataPath函數測試出來的str目錄永遠是不存在的,因為直接return str1,但是testPathExit函數測試的結果卻都是true,說明該目錄存在,并且單步調試過程中進入到斷點ret = true.

在釋出版本中,列印getDataPath傳回的字元串,目錄确實是存在的,傳回結果是/storage/emulate/0/Android/data/test,說明确實傳回return str,目前尚未有任何合理的解釋

     本文轉自fengyuzaitu 51CTO部落格,原文連結:http://blog.51cto.com/fengyuzaitu/1596723,如需轉載請自行聯系原作者

繼續閱讀