简体   繁体   English

如何将 xml 文件从 res/raw 文件夹复制到 android 的 sd 卡?

[英]How to copy a xml file from res/raw folder to sd card of android?

I want to copy a xml file from res/raw folder to the sd card.我想将 xml 文件从 res/raw 文件夹复制到 sd 卡。 This question is actually specific to the ODK Collect.这个问题实际上是特定于 ODK 收集的。 But any help would be appreciated.但任何帮助将不胜感激。 I have looked at Android: How to create a directory on the SD Card and copy files from /res/raw to it?我看过Android:如何在 SD 卡上创建目录并将文件从 /res/raw 复制到它? and other similar posts on the web but I was still unable to copy.和 web 上的其他类似帖子,但我仍然无法复制。 Maybe, its because I am working on ODK Collect.也许是因为我正在开发 ODK Collect。 This is my code for copying the file:这是我复制文件的代码:

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

Thanks in advance.提前致谢。

Try this:尝试这个:

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

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将目录和文件从res / raw文件夹复制到SD卡 - android - Copying directories and files from res/raw folder to sd card - android Android:如何在SD卡上创建目录并从/ res / raw复制文件到它? - Android: How to create a directory on the SD Card and copy files from /res/raw to it? Android Dev Help:将Res / raw或Asset文件夹中的图像保存到SD卡 - Android Dev Help: Saving an image from Res/raw or Asset folder to the Sd card 使用/strings.xml覆盖res / values / strings.xml文件从服务器android下载到SD卡 - Override res/values/strings.xml file with /strings.xml download to sd card from server android 第一次运行时将文件从res / raw复制到sd - copy file from res/raw to sd on first run 如何在Android首次运行应用程序时将文件从我的资产文件夹复制到我的SD卡? - How can I copy a file from my assets folder into my SD card at first run of the app in Android? 将图像从原始文件夹复制到外部SD卡? - Copy image from raw folder to external sd card? Android - 如何使用DDMS将文件夹从文件系统复制到SD卡? - Android - How to copy a folder from File System to SD card using DDMS? Android - 正确地将res / raw资源复制到SD - Android - Copy res/raw resource to SD correctly 当我将文件从原始文件夹移动到android中的SD卡时,文件不会移动 - When i move a file from raw folder to SD card in android, the file won't move
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM