正如hooked82回答的那样,您可以使用 get inputstream
with:
InputStream stream = getResources().openRawResource(R.raw.test123);
然后使用方法将其转换为字符串:
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append((line + "\n"));
}
} catch (IOException e) {
Log.w("LOG", e.getMessage());
} finally {
try {
is.close();
} catch (IOException e) {
Log.w("LOG", e.getMessage());
}
}
return sb.toString();
}
所以你可以用convertStreamToString(stream);
.