简体   繁体   中英

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. From the Android guide i saw this:

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).

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?

Thank you for the help!

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

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() is for reading in the resource, and it gives you an InputStream . You are welcome to write your data to an ordinary file, such as on internal storage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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