I have a method that reads a random joke from a file in raw, and then displays it, but i can’t figure out, how to set a new line.
All the jokes in the line are 1 line, but obviously they are more than one so i use \n. For instance the line says "Hi! \n Hi to you too" When i use my code instead of:
Hi!
Hi to you too
it gives me
Hi! \n Hi to you too
I tried to append it, and that didn’t work with the code bellow also tried to enter the joke in array and then display it from that array, did’t work either… Any ideas would be much appreciated…
InputStreamReader inputStream = new InputStreamReader
(getResources().openRawResource(R.raw.vicove));
BufferedReader br = new BufferedReader(inputStream);
int numLines = 1;
Random r = new Random();
int desiredLine = r.nextInt(numLines);
String theLine="";
int lineCtr = 0;
try {
while ((theLine = br.readLine()) != null) {
if (lineCtr == desiredLine) {
break;
}
lineCtr++;
}
} catch (IOException e) {
e.printStackTrace();
}
textGenerateNumber.setText(String.valueOf(theLine));
I’ve used the same code to read files with no escape characters and it works perfectly…
P.S. Not only \n wouldn’t work, but also \" and probably any other.
try this: