[英]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.