如何在Android的Raw文件夹中写入文件

问题描述:

在我的任务中,我需要在Raw文件夹中读写文件.我做了第一个从我的项目中读取文件的文件,现在我想写入相同的文件.因此,我可以轻松地对该文件进行任何更新.

In my task i need to read and write the file in Raw folder. I did the first one to read the file from my project, Now i want to Write the same file. So it easy for me to make any update in that file.

见此如何将文件写入资产文件夹还是android中的原始文件夹?

我允许用户设置密码,即将通行证写入文件,然后读取通行证并验证其是否匹配.是否可以在原始文件夹中写入文件

I allow the user to set password ie writing the pass into the file then read the pass and validate if it matches. Is it possible to Write file in Raw Folder

"res"文件夹中的任何数据均不可写.您只能从中读取数据.您永远无法将数据即时写入res文件夹.如果您正在寻找一种存储用户名和密码凭据的方法,可以使用共享的偏好

Any data present in the "res" folder is not writable. You can only read data from it. You can never write data to res folder on the fly. If you are looking for a way to store username and password credentials, you can make use of Shared Prefrence

这里是有关如何使用它的示例.

Here is an example on how to use it.

http://marakana.com/forums/android/examples/63.html

编辑1

除非用户使用设置页面中的清除数据"按钮清除数据,否则将永久存储数据到共享首选项"中.导航至设置->管理应用程序->您的应用程序.在这里,您将看到卸载按钮和清除数据按钮. android中的另一件事是您将永远无法保存持久数据.您不能使用首选项,sqlite或文件系统之类的任何数据存储方法来永久存储数据.如果用户要擦除数据,请单击清除数据"按钮,然后数据就消失了.因此,您可以采用这种方式进行编码.

Storing data in Shared Preference is persistent unless user clears the data using "clear data" button in your settings page.Navigate to settings->manage apps->your app. Here you will be seeing uninstall button and clear data button. And one more thing in android is you will never be able to save a persistent data. You can't use any data storage methods like preference, sqlite or file system to store a data for permanent. If user wants to wipe the data he clicks on "Clear Data" button and your data are gone. So you have make your coding in such a way to handle this.

由于这是不可能的,您可以尝试使用应用程序的资源,该资源受写保护并且无法写入.因此,这取决于用户,或者您可能必须使用服务器在那存储数据.

Since this is not possible, you could try to use your app's resources which is write protected and not possible to write to it. So it depends on user or you might have to use your server to store the data over there.