Method for Android to read resource file

Method for Android to read resource file

1. Put it into the resource folder, that is, under the res of the created Android project.

We can create a folder inside and put the files we want to read. For example, create the directory raw in res and put the file abc.bin to be read into this folder. At this time, you can read it through the openrawresource() method. Code is

As long as you get InputStream, everything will be easy!

Note: the directory name under res is particular. The directory template scheduled by the system is located under framework / base / core / RES / res, and must be created according to the name inside. That is, rewrite the system directory! The following resource files can only be named with [a_z0-9], otherwise an error will be reported.

2. Use the openfileinput () method

Because it is a method in contextwrapper and its direct subclass contains activity, it can be used conveniently in activity! The resources inside cannot contain path separators, and can only be placed under the folder / data / package name / files. If the file is not placed in the directory or the pathname is added, a FileNotFoundException will be thrown.

Where data is the final read string!

The above is the detailed explanation of the method of Android reading files. If you have any questions, please leave a message or communicate and discuss with the community of this site. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>