Serious problem with JTextArea
Author |
Message |
Aziz
|
Posted: Fri Jul 08, 2005 2:39 pm Post subject: Serious problem with JTextArea |
|
|
I have a text area...and I get the text from it and write it into a file, but when the text area has a newline in the text area, it writes a weird character (just a box) to the file, and no newline, and when the program reads it again, it doesn't place a newline, just ignores it...Anyhelp? I the program later... |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rizzix
|
Posted: Fri Jul 08, 2005 2:48 pm Post subject: (No subject) |
|
|
yea its the CRLFs & simply LFs issue
where CR represents carriage return and LF stands for line feed...
most unix-like os's and text editors use LFs only, to denote a new line.. ont he othere hand, windows stuff use CRLFs so you might see wierd characters like those boxes when copy-pasting stuff to and from various applications... as for java i'm not sure but i think its just LFs.. hence those crazy characters, instead of a new line. |
|
|
|
|
|
Aziz
|
Posted: Sat Jul 09, 2005 10:11 am Post subject: (No subject) |
|
|
So, how do i get it to show up in my program? Sad
here's the program, btw, source code + classes, and a test file
EDIT: program moved here
EDIT: Okay, SOME progress. instead of using a printwriter's println() method, I used the JTextArea's write() method, and that wrote the actual newlines, but wait, I NOW HAVE AN IDEA....i'll be back.........
EDIT: mother...i just fixed it...so simple, why, why oh so simple??, here's original code used to return a list of chara objects (what stores all the information).
Java: |
//Get the character records
private Chara [] getCharas ()
{
//List of filenames
String[] list = getFileNames ();
//Character list
Chara [] charaList = new Chara [list. length];
//Try to read characters
try
{
//Input stream
BufferedReader input;
//For every file...
for (int i = 0; i < list. length; i++ )
{
//String that holds temporary values
String tempName;
int tempAge;
String tempBday;
String tempDesc = "";
String tempLine;
//Read from character file
input = new BufferedReader(new FileReader("files\\" + list [i ]));
//Read values
tempName = input. readLine(); //read name
tempAge = Integer. parseInt(input. readLine()); //read age
tempBday = input. readLine(); //read bday
//Read description
tempLine = input. readLine();
while (tempLine != null)
{
tempDesc += tempLine;
tempLine = input. readLine();
}
//close file
input. close();
//Create new character//
charaList [i ] = new Chara (tempName, tempAge, tempBday, tempDesc );
}
}//error dialog
catch (IOException e )
{
JOptionPane. showMessageDialog(frame,
"Character list could not be loaded! :(\n" +
e. toString(),
"List Error",
JOptionPane. ERROR_MESSAGE);
}
return charaList;
}
|
Now this part here:
Quote: Java: |
//Read description
tempLine = input.readLine();
while (tempLine != null)
{
tempDesc += tempLine;
tempLine = input.readLine();
}
|
Well, as I was writing the last edit to this post, I thought this idea:
[sytnax="java"]tempDesc += tempLine + "\n";[/syntax]
And it worked. It was reading the lines, but not the actual line feed. Thanks for attempting to help, man, but it was a simple thing i completely missed on my part |
|
|
|
|
|
rizzix
|
Posted: Sat Jul 09, 2005 1:19 pm Post subject: (No subject) |
|
|
right... a simple logic error. *sigh* hehe |
|
|
|
|
|
Aziz
|
Posted: Sat Jul 09, 2005 1:34 pm Post subject: (No subject) |
|
|
Those are always the worst ones huh? Happened quite a bit...but thanks. You're such an inspiration for me (that's like the 5th time you've come in handy! ) |
|
|
|
|
|
|
|