【问题标题】:How to copy a xml file from res/raw folder to sd card of android?如何将 xml 文件从 res/raw 文件夹复制到 android 的 sd 卡?
【发布时间】:2011-07-19 10:47:30
【问题描述】:

我想将 xml 文件从 res/raw 文件夹复制到 sd 卡。这个问题实际上是特定于 ODK 收集的。但任何帮助将不胜感激。我在网上看过Android: How to create a directory on the SD Card and copy files from /res/raw to it? 和其他类似的帖子,但我仍然无法复制。也许是因为我正在开发 ODK Collect。 这是我复制文件的代码:

       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) { }

提前致谢。

【问题讨论】:

  • 是的,它是用于 xforms 等的软件...
  • Collect.FORMS_PATH 的值是多少?
  • Environment.getExternalStorageDirectory() + "/odk/forms"

标签: android


【解决方案1】:

试试这个:

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();

    }

【讨论】:

    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    • 1970-01-01
    • 2011-05-25
    • 2013-11-22
    • 2011-11-15
    相关资源
    最近更新 更多