Android : Android Read a Text file Exactly

on Wednesday, April 15, 2015


I have a text file that has been signed and I need to read this file into a string exactly as it is. The code I am currently using:



BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
invitationText.append(line);
invitationText.append('\n');
}
invitationText.deleteCharAt(invitationText.length()-1);


Works if the file has no return at the end, but if it did have a return then the signature check would fail. There's a lot of questions around this so I'm having a hard time finding one that specifically answer this, so this may be a duplicate question. Some restrictions I have though are:



  • It can't use the methods added in Java 7 (I'm on android, I don't have access)

  • It can't use the org.apache IOUtils method (I can't bring in that library)


Whether it loops or reads the whole thing in one go doesn't matter to me I just need 100% guarantee that regardless of carriage returns in the file, the file will get read in exactly as it is on disk.


0 comments:

Post a Comment