2011-03-28 30 views
0

/android中的數據目錄爲空。我已經安裝了幾個應用程序,並且我還寫了代碼在/ data/Myapp目錄中創建一個文件,無法找到我在Android平板電腦上創建的文件

我在OnCreate方法中有這些行,但運行該程序後沒有在/ data目錄中看到任何文件。

File fileDir = getFilesDir(); 
    String filedir=fileDir.toString(); 
    Log.v("TEST","FILEDIR--->"+filedir); 

     //output i got is FILEDIR--->/data/data/com.android.Test/files 

    String strNewFileName = "test1.txt"; 
    String strFileContents = " MY FIRST FILE CREATION PRGM"; 

    File newFile = new File(fileDir, strNewFileName); 
    try{ 

      boolean filestat = newFile.createNewFile(); 
      Log.v("TEST"," CREATE FILE =>"+ filestat); 

       //output is CREATE FILE =>true indicating success 

      FileOutputStream fo = 
      new FileOutputStream(newFile.getAbsolutePath()); 
      fo.write(strFileContents.getBytes()); 
      fo.close(); 
    } 
    catch(IOException e) 
    {Log.v("TEST","Exception on create ");} 

回答

1

在真實的設備上,如果它沒有固定,就看不到這些文件夾。請參閱this問題。

如果你想寫你的應用程序目錄中的文件,那麼你的代碼是確定的。您可以使用您創建應用程序的相同方式檢查它是否存在 - 從您的應用程序:

File myFile = new File(getFilesDir() + "/test1.txt"); 
if (myFile.exists()) 
{ 
    //Good! 
} 
+0

我的應用程序如何獲得root訪問權限?我嘗試通過「andexplorer」查看,但顯示爲空。 http://www.lysesoft.com/products/andexplorer/ – m4n07 2011-03-28 11:38:14

+0

應用程序無法正常訪問root權限。看到更新的答案。 – MByD 2011-03-28 11:40:30

+0

createNewFile()函數返回true,這意味着該文件在創建時沒有任何問題。但生根適用於平板電腦?假設我正在開發獲取輸入的應用程序,並將處理後的輸入存儲在「/data/com.android.mypackage/files」中。假設用戶有興趣查看我創建的文件,那麼用戶無法使用我的應用程序而不生根? – m4n07 2011-03-28 12:00:00

相關問題