简体   繁体   English

写位于/ raw文件夹中的txt文件

[英]Write in a txt file located in /raw folder

here's my problem. 这是我的问题。

I have a txt file in the /raw folder and I want to write into it. 我在/ raw文件夹中有一个txt文件,我想写入其中。 From the Android guide i saw this: 在Android指南中,我看到了以下内容:

Tip: If you want to save a static file in your application at compile time, save the file in your project res/raw/ directory. 提示:如果要在编译时将静态文件保存在应用程序中,请将该文件保存在项目res / raw /目录中。 You can open it with openRawResource(), passing the R.raw. 您可以使用openRawResource()并通过R.raw来打开它。 resource ID. 资源ID。 This method returns an InputStream that you can use to read the file (but you cannot write to the original file). 此方法返回一个InputStream,您可以使用该InputStream来读取文件(但是不能写入原始文件)。

So in my code I did this: 所以在我的代码中,我这样做:

FileOutputStream myFile = openRawResource(R.raw.max_easy, Context.MODE_PRIVATE);

But gives me error in openRawResource()... How do i solve this? 但是给我openRawResource()中的错误...我该如何解决?

Thank you for the help! 感谢您的帮助!

I have a txt file in the /raw folder and I want to write into it 我在/ raw文件夹中有一个txt文件,我想写进去

That is not possible at runtime. 在运行时这是不可能的。 Resources and assets are read-only at runtime. 资源和资产在运行时是只读的。

But gives me error in openRawResource()... How do i solve this? 但是给我openRawResource()中的错误...我该如何解决?

openRawResource() is for reading in the resource, and it gives you an InputStream . openRawResource()用于读取资源,它为您提供InputStream You are welcome to write your data to an ordinary file, such as on internal storage . 欢迎您将数据写入普通文件,例如内部存储器上

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM