2012-03-28 89 views
0

我需要將我應用程序資產文件夾中的所有文件複製到SD卡中,以便我可以通過我的web服務中的更新來寫入此文件夾。但是,我似乎無法找到正確的路徑。下面是我目前正在使用其工作是一個數據庫,通過複製代碼:android-從資產文件夾中複製文件

public PluginResult execute(String arg0, JSONArray arg1, String arg2) 
{ 
    String[] resourseFileNames = {"file1.html","file2.html"}; 
    final int length = resourseFileNames.length; 

    try 
    { 
     String pName = this.getClass().getPackage().getName(); 
     this.copyOriginal("Databases.db","/data/data/"+pName+"/app_database/"); 
     this.copyOriginal("0000000000000001.db","/data/data/"+pName+"/app_database/file__0/"); 
     for(int i=0; i<length; i++) 
     { 
      this.copyOriginal("file:///android_asset/www/" + resourseFileNames[i],"file:///SDCard/MYAPP/www/" + resourseFileNames[i]); 
     } 
    } 
    catch (IOException e) 
    { 
     System.err.println("Caught IOException: " + e.getMessage()); 
    } 
} 

void copyOriginal(String file, String folder) throws IOException 
{ 
    File CheckDirectory; 
    CheckDirectory = new File(folder); 
    if (!CheckDirectory.exists()) 
    { 
    CheckDirectory.mkdir(); 
    } 

    OutputStream out = new FileOutputStream(folder+file); 
    InputStream in = this.ctx.getAssets().open(file); 
    byte[] buf = new byte[1024]; 
    int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len); 
    in.close(); 
    out.close();  
} 

這裏的任何幫助,將不勝感激,我相信我靠近,它的文件路徑,我相信是錯了,因爲我不斷收到錯誤(logcat的 - '我的文件路徑defienet'(沒有這樣的文件或目錄)

感謝

回答

0

這似乎是什麼?我上面的代碼是正確的,它不工作的原因是由於我的傳輸文件太大。最簡單的解決方案是將我的固件升級到2.3.3 +

0

有你在你的manifest文件這一行

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+0

是的我擁有這個功能,在複製數據庫文件時以minf顯示上述工作,但對於其他文件例如失敗。 file1.html謝謝 – 2012-03-28 14:47:59

相關問題