1

I'm currently trying to read a file from (res/raw) by using an InputStream that I dimension like such:

InputStream mStream = this.getResources().openRawResource(R.raw.my_text_file_utf_8);

I then put that into this method to return the values:

public List<String> getWords(InputStream aFile) {

List<String> contents = new ArrayList<String>();
try {
  BufferedReader input =  new BufferedReader(new InputStreamReader(aFile));          
  try {
    String line = new String();//not declared within while loop
    while ((line = input.readLine()) != null ){              
        contents.add(line);
    }
  }
  finally {
    input.close();
  }
}
catch (IOException ex){
  ex.printStackTrace();
}

return contents;

}

My problem: It reads all the values as it should, but say if the file is 104 lines long, it will actually return a value of something like 134 total lines with the remaining 30 lines being full of null??

Have checked: Already using UTF-8 format, and double checked that there are literally no blank lines within the document itself...

I thought the way the while loop was written that it couldn't record a line=null value to contents List? Am I missing something here?

Thanks for any constructive information! I'm pretty sure I'm overlooking some simple factoid here though...

While-E
  • 1,527
  • 2
  • 20
  • 37

1 Answers1

0

Why dont you create HTML for your information and then parse it.

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
  • Using it for a number of static byte arrays. Not sure where HTML would get me any better performance, other than solving the current problem. I'd then have to rewrite a ton of code to work with HTML instead... Thanks for the suggestion though. – While-E Sep 22 '11 at 20:06