The question "How to read a local (res/raw) file line by line?" deals with a similar issue but I was unable to construct a solution base on the answers provided there. I did get a very useful piece of info (the DataInputStream class which has a readLine method), and I have been researching this on the developer website and trying to make it work.
What I am trying to do is read information stored in successive lines of a text file into a string array, such that the first line is the first array element, the second line is the next array element, etc... and then this string array is going to be used to populate text fields in the next activity that is opened. This is all happening inside of a switch case (depending on the case i.e. which list item is selected, a different text file is loaded). Here is what I have so far:
//Retrieve necessary text file for inputstream
InputStream buildinginfo = getResources().openRawResource(R.raw.testbuilding);
class DataInputStream extends FilterInputStream{
protected DataInputStream(InputStream buildinginfo) {
super(buildinginfo);
// TODO Auto-generated constructor stub
int i;
String[] building_info;
//Assign lines of text to array
for(i=0; i<5; i++){
building_info[i] = buildinginfo.readLine();
}
}
}
So far the editor is okay with it except for these errors, and I am not experienced enough to make sense of them. I understand what they are saying but not how to fix them. The errors are in the section inside the switch case where I am trying to set up the input stream and assign the values. Most importantly, in the line where the readLine command takes place, I get: "- The method readLine is undefined for the type DataInputStream" "- The method readLine is undefined for the type InputStream"
This I do not understand because if I am not mistaken, it says here (http://developer.android.com/reference/java/io/DataInputStream.html) that the DataInputStream class has the readLine method available (I found out about this from the question referred to above). Obviously I have not used the DataInputStream correctly, but I can't seem to figure out how. I have looked through several questions on here and referred to the page linked above several times.
If anybody can see what I am doing wrong I would appreciate your help very much. If I am barking up the wrong tree entirely for this type of task, I apologize for wasting time, but some guidelines or a referral to an appropriate tutorial resource would be much appreciated. I have spent the last two days trying to figure out these errors.