1. 程式人生 > >android 讀取本地檔案的一種方式

android 讀取本地檔案的一種方式

try {
String fileUri = "layout.xml";


InputStream is =MainApplication.getInstance().getAssets().open(fileUri);


int size = is.available();// Read the entire asset into a local byte

    byte[] buffer = new byte[size];
is.read(buffer);
is.close();// Convert the buffer into a string.



content = new String(buffer, "gb2312");
} catch (Exception e) {
// TODO: handle exception
}