Re: Reading a text file
On 2/11/2011 9:55 PM, bruce wrote:
On Feb 11, 9:51 pm, Eric Sosman<esos...@ieee-dot-org.invalid> wrote:
On 2/11/2011 9:26 PM, bruce wrote:
I am reading a file with
BufferedReader reader = null;
StringBuffer contents = new StringBuffer();
while ((text = reader.readLine()) != null) {
contents.append(text)
.append(System.getProperty(
"line.separator"));
}
This code reads the file fine. My problem is that when I put the data
into a text, it is displayed with a space character before ever
character. (bruce => b r u c e)
What am I doing wrong??
Something in the "it is displayed" code would be my guess.
This is how I am displaying the input text:
txtText.setText(contents.toString());
Is that the wrong way to insert the file data (contents) into the text
area (txtText)?
Sorry: I can't get your code to compile, much less run and
exhibit desirable or undesirable behavior.
(In other words, STOP dripping your code out line by line by
incomplete out-of-context line! "Doctor, it hurts!" "What hurts?"
"Even worse than yesterday!" Please provide code that is SHORT and
SELF-CONTAINED and COMPLETE and COMPILABLE. Yes, including the
package and imports and class lines: Something someone who feels like
being helpful can dump AS IS through his Java compiler and see what
happens. I can't debug what I can't see. Stop teasing!)
--
Eric Sosman
esosman@ieee-dot-org.invalid