2

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

in the below line,

content = storedData + content + "\n";
//content = a word received from EditText
//storedData = content read from a stored file. 
Prabha Vathi
  • 337
  • 1
  • 4
  • 10

1 Answers1

1

replace this:

String lines[] = storedData.split("\\n");

with

String lines[] = storedData.split("\n");

Actually your lines[] is containing only one line no splits occurs. try that.

anubhava
  • 664,788
  • 59
  • 469
  • 547
Pradip
  • 2,993
  • 3
  • 20
  • 27
  • do `Sysout(storedData)`, verify what you actually writtent in the file. If problem is there the you need to change there. – Pradip Sep 06 '13 at 09:07
  • it is android app. how can i do that? just entering will give the output? `The method Sysout(String) is undefined for the type DisplayActivity` i tried to put it `textbox.setSet(Sysout(storedData));` – Prabha Vathi Sep 06 '13 at 09:07
  • No, i have asked you to put `System.out.print(storedData)` in your code, which will help you to get content of storedData. you have to check the `System.out.print data` from **LogCat**. – Pradip Sep 06 '13 at 09:15
  • @PrabhaVathi I agree that,It's a weird problem, but how about putting a breakpoints and watching there ? – Suresh Atta Sep 06 '13 at 09:24
  • I can't find any output in LogCat. I tried all verbose, error, info.. By the way, If i change like this, `content = storedData + content + "::";` and `storedData.split("::");` I am getting the complete array and loop works good. does it give any idea? – Prabha Vathi Sep 06 '13 at 09:26
  • Ok, it's not a problem. you can find that By doing a serch by keyword `System.out`. – Pradip Sep 06 '13 at 09:35