2012-06-02 244 views
0

我有一個文件位於我的虛擬。我試圖做到這一點:打開本地文件Android

File file = new File("invoice2.xml"); 
    if (file.exists()) { 
    textview1.setText("file exists"); 
    } 
    else{ 
    textview1.setText("file dosen't exist"); 
    } 

這顯示「文件存在」。我使用Eclipse和根據DDMS文件瀏覽器我的「invoice2.xml」文件位於

數據/數據/ invoicing.digital.namespace /文件/ invoice2.xml

我在做什麼錯?我如何獲得「文件存在」結果? 謝謝

編輯:這工作文件文件=新文件(MyActivity.this.getFilesDir(),「invoice2.xml」);

+0

如果可能的話最好把在原料或資產 –

回答

3

看起來像你想讀從根文件夾。試試這個辦法:

File file = new File(mContext.getFilesDir() + "invoice2.xml"); 
+0

哦,那太棒了!有效!謝謝! :) –

0

如果可能的話最好把在原料或資產 或 文件名應該是這樣的 System.getProperty(「FILESDIR」)+文件分割符+ YOUR_INTERNAL_FILE_NAME

+0

謝謝,howver我不想移動的文件。 –