代碼
public String getFromAssets(String fileName){
try {
InputStreamReader inputReader = new InputStreamReader( getResources().getAssets().open(fileName) );
BufferedReader bufReader = new BufferedReader(inputReader);
String line="";
String Result="";
while((line = bufReader.readLine()) != null)
Result += line;
return Result;
} catch (Exception e) {
e.printStackTrace();
}
}
//從assets 文件夾中獲取文件並讀取數據
public String getFromAssets(String fileName){
String result = "";
try {
InputStream in = getResources().getAssets().open(fileName);
//獲取文件的字節數
int lenght = in.available();
//創建byte數組
byte[] buffer = new byte[lenght];
//將文件中的數據讀到byte數組中
in.read(buffer);
result = EncodingUtils.getString(buffer, ENCODING);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}