将文件复制到android中的资产文件夹 [英] Copying files into asset folder in android

查看:170
本文介绍了将文件复制到android中的资产文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到将某些文件复制到android中的asset文件夹中的任何方法.我必须通过互联网读取一个文件并将其保存到android中的资产文件夹中. 所有示例/教程都讨论了如何从资产文件夹复制文件,但没有一个讨论了相反的方法.

I couldn't find any way to copy some files into asset folder in android. I have to read one file over internet and save it into asset folder in android. All the examples/tutorials talk about copying files from asset folder but none talks about the other way round.

对此我将不胜感激.预先感谢.

I will appreciate any example for this. Thanks in advance.

推荐答案

将apk安装到设备中后,您将无法修改资产. 为什么? 当您将应用程序安装到设备中时,所有资源(包括src,资产,库,资源等)都将被归档到APK文件中. APK文件可以被视为RAR或ZIP文件.就像存档后无法修改RAR一样,您也无法修改APK.

You cannot modify assets after installing apk into your device. Why? When you install your app into your device, all the resources including src, assets, libs, res etc. are sort of archived into an APK file. APK file can be thought of as a RAR or ZIP file. Just like you can't modify a RAR after archiving, you can't modify APK.

您所要做的就是获得指向外部存储(SD卡)或内部存储(下载文件夹)的指针,并使用它来保存您下载的文件.

All you have to do is get a pointer to external storage (SDcard) or internal storage (Downloads folder) and use it to save files you download.

示例:

/*Using external directory*/

String folder = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "youfilename";
OutputStream output = new FileOutputStream(folder + "\" + fileName);

/*whenever you read input from url (inside the while loop)*/
output.write(bytearray, offset, bytecount)

这篇关于将文件复制到android中的资产文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆