I am developing an android app and i need it to read a text file. Once it has read the text file I need to save certain parts
to a database.
The text file contains the following:
Title - Hello
Date - 03/02/1982
Info - Information blablabla
Title - New title
Date - 04/05/1993
Info - New Info
I thought that I need to split the text file in two by using the blank line as a separator
. Then I need to get the individual info like the Title and save it into the database as a title. Is there some way to do this? I know how to read all of the text file. I am using this to read the complete
text file.
TextView helloTxt = (TextView) findViewById(R.id.hellotxt);
helloTxt.setText(readTxt());
}
private String readTxt() {
InputStream inputStream = getResources().openRawResource(R.raw.hello);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1) {
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return byteArrayOutputStream.toString();
}
I was just wondering about the splitting event of this. Thank you