A011-raw resources, rawstrokes Resources

Source: Internet
Author: User

A011-raw resources, rawstrokes Resources

The previous article introduced assets resources. This section describes the raw resources in the res directory and the path is res/raw. In addition to processing assets resources, the resource files involved in our program are all under the res directory, such as the drawable and menu resources described earlier. Other resource types will be introduced later.

How do we obtain raw resources? What are the similarities and differences between the resources in the assets Directory? This is what Android Developers need to pay attention.
Commonalities
Both of them will not be compiled into binary files, that is, they will not be packaged into the apk file.

Differences
-Assets are not mapped to the R file, while raw resources are mapped to the R file.
-Raw resources can be referenced through R. raw. filename.
-Assets can have a directory structure, while raw cannot.

Eg: Read txt files under res/raw

Public void readRaw () {InputStream inputStream = getResources (). openRawResource (R. raw. demo); textView. setText (read (inputStream);} private String read (InputStream inputStream) {try {ByteArrayOutputStream osStream = new ByteArrayOutputStream (); int length; while (length = inputStream. read ())! =-1) {osStream. write (length);} return osStream. toString ();} catch (IOException e) {return "file read/write failed ";}}

Reference: http://www.cnblogs.com/leizhenzi/archive/2011/10/18/2216428.html

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.