I had the same question, and although the answers above are probably correct, I could not get them to work successfully. This is almost certainly an operator error and ignorance on my part - but just in case someone wants to see me - n00b - finally do it, here is my solution:
// this is just the click handler for a button... public void loadStatesHandler(View v) { try { String states = getStringFromRaw(this); readOutput.setText(states); } catch(Throwable t) { t.printStackTrace(); } } private String getStringFromRaw(Context c) throws IOException { Resources r = c.getResources(); InputStream is = r.openRawResource(R.raw.states); String statesText = convertStreamToString(is); is.close(); return statesText; } private String convertStreamToString(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = is.read(); while (i != -1) { baos.write(i); i = is.read(); } return baos.toString(); }
I’m not quite sure why this worked for me when it wasn’t higher, because it does not look fundamentally different, but, as I said, it was probably an operator error on my part.
Bennett von bennett
source share