Usually, if the Android developer has some files such as audio, video,. Html,.mp3, etc. these files do not want the compiler to compile and keep the original originals packaged into the APK file (which is common and common in game development, such as game music, graphs and other resources), Then you can use Android in the Res directory Res/raw save. Files in the Res/raws directory will not be compiled by Android into binary, and Android will keep these files intact and packaged into the APK file at the end of the compilation release.
How to read raw files:
1 PackageCom.zzw.testraw;2 3 ImportJava.io.BufferedInputStream;4 ImportJava.io.ByteArrayOutputStream;5 Importjava.io.IOException;6 ImportJava.io.InputStream;7 8 Importandroid.app.Activity;9 ImportAndroid.os.Bundle;Ten ImportAndroid.util.Log; One A Public classMainactivityextendsActivity { - - Private Static FinalString TAG = "Mainactivity"; the - @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); + //Setcontentview (r.layout.activity_main); - + Readraw (); A } at - Private voidReadraw () { -InputStream is =getresources (). Openrawresource (R.raw.hello); - - Try { - byte[] data =Readbytedatafrominputstream (IS); inString content =NewString (data, 0, Data.length, "UTF-8")); - log.d (TAG, content); to}Catch(IOException e) { + e.printstacktrace (); - } the * } $ Panax Notoginseng Private byte[] Readbytedatafrominputstream (InputStream is)throwsIOException { -Bufferedinputstream bis =NewBufferedinputstream (IS); the +Bytearrayoutputstream BAOs =NewBytearrayoutputstream (); A the Final intBuffer_size = 2 * 1024; + - intc = 0; $ byte[] buffer =New byte[buffer_size]; $ - //the reason for writing baos.write (buffer, 0, c) is how much to read - while((c = bis.read (buffer))! =-1) { theBaos.write (buffer, 0, c); - Baos.flush ();Wuyi } the - byte[] data =Baos.tobytearray (); Wu Baos.flush (); - About baos.close (); $ is.close (); - - returndata; - A } +}
Storage and reading of Res/raw files