編輯:關於android開發
通常,如果Android開發者有些文件比如音頻,視頻,.html,.mp3等等這些文件不希望編譯器編譯而保持原始原貌打包進apk文件(這在游戲開發中很常見和普遍,如游戲用到的游戲音樂、圖等資源),那麼可以使用Android在res目錄下的res/raw保存。res/raws目錄下的文件將不被Android編譯成二進制,Android將這些文件資源保持原狀原封不動的打包進最終編譯發布時候的apk文件。
怎樣讀取raw文件:
1 package com.zzw.testraw; 2 3 import java.io.BufferedInputStream; 4 import java.io.ByteArrayOutputStream; 5 import java.io.IOException; 6 import java.io.InputStream; 7 8 import android.app.Activity; 9 import android.os.Bundle; 10 import android.util.Log; 11 12 public class MainActivity extends Activity { 13 14 private static final String TAG = "MainActivity"; 15 16 @Override 17 protected void onCreate(Bundle savedInstanceState) { 18 super.onCreate(savedInstanceState); 19 // setContentView(R.layout.activity_main); 20 21 readRaw(); 22 } 23 24 private void readRaw() { 25 InputStream is = getResources().openRawResource(R.raw.hello); 26 27 try { 28 byte[] data = readByteDataFromInputStream(is); 29 String content = new String(data, 0, data.length, "UTF-8"); 30 Log.d(TAG, content); 31 } catch (IOException e) { 32 e.printStackTrace(); 33 } 34 35 } 36 37 private byte[] readByteDataFromInputStream(InputStream is) throws IOException { 38 BufferedInputStream bis = new BufferedInputStream(is); 39 40 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 41 42 final int BUFFER_SIZE = 2 * 1024; 43 44 int c = 0; 45 byte[] buffer = new byte[BUFFER_SIZE]; 46 47 // 寫成baos.write(buffer, 0, c)的原因是讀多少寫多少 48 while ((c = bis.read(buffer)) != -1) { 49 baos.write(buffer, 0, c); 50 baos.flush(); 51 } 52 53 byte[] data = baos.toByteArray(); 54 baos.flush(); 55 56 baos.close(); 57 is.close(); 58 59 return data; 60 61 } 62 }
Android Gradle Build Error:Some file crunching failed, see logs for details解決辦法,gradl
Android 手機衛士--導航界面4的業務邏輯,android衛士本文實現導航界面4的業務邏輯,導航界面4的界面如下: 本文地址:http://www.cnblogs
SwipeRefreshLayout下拉刷新,swiperefreshlayout1.SwipeRefreshLayout是Google在support v4 19.1版
android入門系列- TextView EditText Button ImageView 的簡單應用,textviewedittext 第一篇原創,其實