2012-01-22 109 views
1

我的應用程序創建一個文本文件。我希望用戶能夠輕鬆訪問這些文件。我把這個文本文件寫在SD卡上。我想讓用戶用其他程序編輯文件。
我使用文件資源管理器查看這些文件,但無法使用文件管理器查看。如何爲其他應用程序編寫可讀文件?

String extPath = Environment.getExternalStorageDirectory().getAbsolutePath(); 
     try{ 
    String pathPrefix = extPath + "/Android/data/" +  getApplication().getPackageName() + "/cache/"; 
    //File extPathFile = getExternalFilesDir(pathPrefix+FileName); 
    Log.d("TAG", "pathPrefix="+pathPrefix); 
    Log.d("TAG", "FileName="+FileName); 
    File file = new File(pathPrefix, FileName+".txt"); 
    if(file.exists()){ 
    Log.d("TAG", "File("+pathPrefix+FileName+")exist"); 
    }; 
    OutputStreamWriter outStream = 
      new OutputStreamWriter(new FileOutputStream(file)); 

的logcat:

01-22 14:26:15.834: D/TAG(14290): pathPrefix=/mnt/sdcard/Android/data/mast.avalons/cache/ 
01-22 14:26:15.834: D/TAG(14290): FileName=S000004_21-10-2011 
01-22 14:26:16.044: D/TAG(14290): java.io.FileNotFoundException: /mnt/sdcard/Android/data/mast.avalons/cache/S000004_21-10-2011.txt (No such file or directory) 

謝謝!

回答

2

我想你應該創建中間目錄:

new File(pathPrefix).mkdirs(); 
+0

+1由於做工精細! – MastAvalons

相關問題