storing a string

Im reading a string from a server, how can I store it in a variable before displaying it?, the code below just displays the string.

while( ( buffer = input.readLine() ) != null )
          display.appendText( "\n" + buffer ) ;
          }
eire_irelandAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Just save it to a variable. Of course it will be overwritten each time in the loop

String savedString = buffer;
0
CEHJCommented:
What is it you're trying to achieve?
0
imladrisCommented:
How about:

String store="";
while( (buffer=input.readLine())!=null)
{   store+=buffer;
    display.appendText("\n"+buffer);
}

This will put the whole input into the String named stored.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mick BarryJava DeveloperCommented:
String buffer = null ;
   StringBuffer todisplay = new StringBuffer();
        while( ( buffer = input.readLine() ) != null )
          todisplay.append( "\n" + buffer ) ;
          }
    display.setText(todisplay.toString());
0
Mick BarryJava DeveloperCommented:
use following if you want to append the read text:

display.appendText(todisplay.toString());
0
jimmackCommented:
It's already stored in a variable in your question.  It's stored in "buffer".
0
CEHJCommented:
If 'display' is a text component like a TextArea then it's stored anyway and you can get it back as follows:

String original = display.getText();
0
Mick BarryJava DeveloperCommented:
> It's stored in "buffer".

Not the entire string read.

> String original = display.getText();

That returns the string displayed in the text field, and not the string read in.
0
CEHJCommented:
>>That returns the string displayed in the text field, and not the string read in.

The value, if taken just after the text field is set, is exactly the same as the value contained in the StringBuffer 'todisplay' that you suggested, which is redundant if 'display' is a text component of some kind, as the String is already buffered.
0
eire_irelandAuthor Commented:
Cheers bucks
0
CEHJCommented:
What does type does 'display' refer to eire_ireland?
0
eire_irelandAuthor Commented:
A string, I dont think i know what u mean
0
CEHJCommented:
>>display.appendText()

'display' can't be of type String, as it does not have an appendText method
0
eire_irelandAuthor Commented:
well im using display.appendText, whats has this to do with anything anyway
0
CEHJCommented:
Never mind - i don't want to labour the point!
0
eire_irelandAuthor Commented:
Fair enough, I was worried there for a second that you were lookin for advice off me!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.