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

Write in a txt file located in /raw folder

这是我的问题。

我在 /raw 文件夹中有一个 txt 文件,我想写入其中。 从 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. You can open it with openRawResource(), passing the R.raw. resource ID. This method returns an InputStream that you can use to read the file (but you cannot write to the original file).

所以在我的代码中我这样做了:

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

但是在 openRawResource() 中给我错误...我该如何解决这个问题?

感谢您的帮助!

I have a txt file in the /raw folder and I want to write into it

这在运行时是不可能的。资源和资产在运行时是只读的。

But gives me error in openRawResource()... How do i solve this?

openRawResource() 用于阅读资源,它给你一个 InputStream。欢迎您将数据写入普通文件,例如 internal storage.