Input stream to string is explained how to read the data public String inputStreamToString(InputStream is) throws IOException { StringBuffer sBuffer = new StringBuffer(); DataInputStream dataIO = new DataInputStream(is); String strLine = null;
Retrieve an input stream of the required raw file Create an instance of DataInputStream which reads the previous stream as input. Read line by line until we reach the end of file and append each line to a stringbuffer Close the dataInputstream InputStream iFile = getResources().openRawResource(R.raw.quizhelp); try { TextView helpText = (TextView) findViewById(R.id.TextView_HelpText); String strFile = inputStreamToString(iFile); helpText.setText(strFile); } catch (Exception e) { Log.e(DEBUG_TAG, "InputStreamToString failure", e); }
public String inputStreamToString(InputStream is) throws IOException { StringBuffer sBuffer = new StringBuffer(); DataInputStream dataIO = new DataInputStream(is); String strLine = null;
First create StringBuffer, DataInputStream and a String
ReplyDeleteStringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = null;
Then read the file and store it in the string
while ((strLine = dataIO.readLine()) != null) {
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
InputStream iFile = getResources().openRawResource(R.raw.quizhelp);
ReplyDeletetry {
TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
Log.e(DEBUG_TAG, "InputStreamToString failure", e);
}
// Read raw file into string and populate TextView
ReplyDeleteInputStream iFile = getResources().openRawResource(R.raw.quizhelp);
try {
TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
Log.e(DEBUG_TAG, "InputStreamToString failure", e);
}
InputStream iFile = getResources().openRawResource(R.raw.quizhelp);
ReplyDeletetry {
TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
}
Input stream to string is explained how to read the data
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = null;
while ((strLine = dataIO.readLine()) != null) {
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
}
Retrieve an input stream of the required raw file
ReplyDeleteCreate an instance of DataInputStream which reads the previous stream as input.
Read line by line until we reach the end of file and append each line to a stringbuffer
Close the dataInputstream
InputStream iFile = getResources().openRawResource(R.raw.quizhelp);
try {
TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
Log.e(DEBUG_TAG, "InputStreamToString failure", e);
}
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = null;
while ((strLine = dataIO.readLine()) != null) {
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
}
Input Stream iFile = getResourses ().openRawResource(R.raw.quizhelp);
ReplyDeletetry {
TextView helpText = (TextView) findViewById(R.id.TextView_HelpText);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
Log.e(DEBUG_TAG, "InputStreamToString failure", e);
}
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStram dataIO = new DataInputStream(is);
String strLine = null;
while ((strLine = dataIO.readLine()) != null) {
sBuffer.append(strLine + "\n");
}
dataIO.close();
is.close();
return sBuffer.toString();
}