2011-07-19 17 views
2

xmlファイルをres/rawフォルダからsdカードにコピーしたいとします。この質問は、実際にはODK Collectに固有です。しかし、どんな助けもありがとう。私はAndroid: How to create a directory on the SD Card and copy files from /res/raw to it?とウェブ上の他の同様の投稿を見てきましたが、まだコピーできませんでした。多分、私はODK Collectに取り組んでいるからです。事前にxmlファイルをres/rawフォルダからアンドロイドのsdカードにコピーする方法は?

 try { 
     InputStream in = getResources().openRawResource(R.raw.problem2); 
     OutputStream out = new FileOutputStream(Collect.FORMS_PATH+"/problem2"); 

       // Transfer bytes from in to out 
       byte[] buf = new byte[1024]; 
       int len; 
       while ((len = in.read(buf)) > 0) { 
        out.write(buf, 0, len); 
       } 
       in.close(); 
       out.close(); 

     }   
    catch(IOException e) { } 

ありがとう: これは、ファイルをコピーするための私のコードです。

+0

ODK収集しますか...? – Mudassir

+0

ええと、xformsなどのソフトウェア... – Kartikey

+0

Collect.FORMS_PATHの値は何ですか? –

答えて

0

はこれを試してみてください:

private void copyFiles() throws IOException{ 

     InputStream myInput = m_Context.getAssets().open(FILE_NAME_KEPT_IN_ASSET_FOLDER); 
     String outFileName = "/data/data/your.package.name/folder/"; 
     OutputStream myOutput = new FileOutputStream(outFileName); 
     byte[] buffer = new byte[1024]; 
     int length; 
     while ((length = myInput.read(buffer))>0){ 
      myOutput.write(buffer, 0, length); 
     } 
     myOutput.flush(); 
     myOutput.close(); 
     myInput.close(); 

    } 
+0

残念ながら、それはうまくいきませんでした。しかし、ありがとう。 – Kartikey

関連する問題