Android - 讀取assets的檔案(.json)

把檔案都丟在專案的根目錄下的assets,如果沒有的話就自己建一個~

try { AssetManager assets = getAssets(); InputStream inputStream =null; inputStream = assets.open("job.json"); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); StringBuffer sb = new StringBuffer(); String line = ""; while ((line = br.readLine()) != null) { sb.append(line); } Log.d("shawn929", "" + sb.toString()); br.close(); }catch(Exception e){ e.printStackTrace(); }

urShawn