在Android应用程序更新的原始资源 [英] Updating a raw resource in an Android app

查看:130
本文介绍了在Android应用程序更新的原始资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序应该有的数据存储在一个文本文件中。每次当应用程序启动时,时间数据读取和每一个应用程序被关闭数据时间是从文本文件和新的数据对上次会议被保存消灭了。

my app is supposed to store some data in a text file. Every time when the app is started the data is read and every time the app is closed the data is wiped out from the text file and new data about the last session is saved.

现在我没有问题读取数据:

Now I don't have problem reading in data:

InputStream is = getResources().openRawResource(R.raw.myFile);
BufferedReader br = new BufferedReader(new InputStreamReader(is));

麻烦的是,当我写文件。显然,这必须由资源莫名其妙地访问,但 R.raw.myFile 仅造成InputStream和我有一个字符串传递给 openFileOutput 。这是有问题的code:

The trouble is when I write to the file. Obviously it has to be accessed somehow by the resources but R.raw.myFile results only in InputStream and I have to pass a string to the openFileOutput. This is the code in question:

FileOutputStream fos = openFileOutput(getResources().openRawResource(R.raw.myFile), MODE_PRIVATE);

如此看来,这是不行的。是否有任何其他的方式来写入文件中的原始文件夹?

So it seems that this won't work. Is there any other way to write to the file in the raw folder?

推荐答案

如果你想写包装在原始文件夹中的文件,你必须首先复制到本地文件系统。在您的项目包含在您的原始目录的资源将被打包的APK内,不会在运行时可写的。想想看内部或的外部数据存储的API。

If you want to write to a file packaged in the raw folder, you will have to copy it to the local file system first. Resources contained in your raw directory in your project will be packaged inside your APK and will not be writeable at runtime. Consider looking at the Internal or External Data Storage APIs.

这篇关于在Android应用程序更新的原始资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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