Friday, 6 September 2013

newline - not added or unable to split by newline

newline - not added or unable to split by newline

I am reading android. So, It is just for practice.
String storedData = readData();
String lines[] = storedData.split("\\n");
int linesLength = lines.length;
for(int i = 0; i < linesLength; i++) {
tmp = "it is me " + tmp + lines[i] + "\r\n";//i have assigned
all the variables.
}
textbox.setText(tmp);
Everything is displayed in single line.
String lines[] = storedData.split("\\n");
String lines[] = storedData.split("\r\n");
String lines[] = storedData.split("\\r?\\n");
String lines[] = storedData.split("\n");
Tried all the above. Not working for me.
This is how i have written the text in a file.
Am i writing the new content in the storedData with newline? Is that
correct? I assume storedData has a newline in the end. So i join the
content and add a newline in the end.
content = storedData + content + "\n";
outputStream = openFileOutput(FILENAME, Context.MODE_PRIVATE);
outputStream.write(content.getBytes());
outputStream.close();
it is always displaying the output in single line.
textbox.setText(tmp);
it is me test test1 test2

No comments:

Post a Comment