Saving problem ?

HI

i getText from the textarea and saves it in to string like this...

String retreive = textarea.getText();

try

{

RandomAccessFile logfile =new RandomAccessFile("c:\\saved.txt","rw");

logfile.writeBytes(retreive);

}

catch(IOException e)

{

System.out.println("cannot write on to log file....");

}

If i entered any 'enter' keys the program will run smoothly and save it into file..

But the problem is when i press enter there is a square symbol in the saved file...

How can i save it to the file as i entered in textarea...

Is there any idea without that square symbol...

Would anybody please tell me......

[988 byte] By [Reona] at [2007-11-27 2:56:17]
# 1
String retreive = textarea.getText().trim() ; I guess, it might be the empty space " ". Remove the empty space
AnanSmritia at 2007-7-12 3:33:49 > top of Java-index,Java Essentials,Java Programming...
# 2
No trim() womt work here , i tried , it will only ignore spaces...the problem is how to avoid that square will saving it to a file....
Reona at 2007-7-12 3:33:49 > top of Java-index,Java Essentials,Java Programming...
# 3
i guess there is a new line \n character which is saved with the string,i think you should control where it is coming from .is this all of your code ?
ayberka at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 4
the string is getting all the new lines i typed inside textarea but the problem is when i press enter key the saved file will place a square instead of enter key...I want to keep the file as i typed inside the textarea...
Reona at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 5
use bufferwrited instead of randomaccessfile
aaa801a at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 6
You should also take a look at the read/write methods of JTextArea. I've had success with those maintaining proper line separators in the past.
echarila at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 7
try thisretreive=retreive.replaceAll("\n", "\r\n");ayberk cansever
ayberka at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 8
Did u mean read / write in randomaccessfile orin jtextare....
Reona at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 9
ayberk you are great it works...\n means next line...so wat is \r....
Reona at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 10
> Did u mean read / write in randomaccessfile orin> jtextare....I mean the methods in JTextArea. The read method takes a Reader and the write method takes a Writer. You don't have to mess around with files directly, or replacing characters in the String.
echarila at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 11
What is your motivation for using a RandomAccessFile? That seems the oddest choice possible.
DrLaszloJamfa at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 12
i had never seen such things before in JTextarea ..If you dont mind please give me some hints ...
Reona at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 13
I only used RandomAccessFile and FileOutputStream...Is there any problem choosing this one...?Is there any other classes like this....?
Reona at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 14
> only used RandomAccessFile Do you know the story of the carpenter who only had a hammer?You should take the IO tutorial: http://java.sun.com/docs/books/tutorial/essential/io/index.html
DrLaszloJamfa at 2007-7-12 3:33:50 > top of Java-index,Java Essentials,Java Programming...
# 15
> I only used RandomAccessFileAlso: your mileage may vary, but I've written lots of IO code over the years,as most Java developers do, and I've never needed to use RandomAccessFile.
DrLaszloJamfa at 2007-7-21 20:37:16 > top of Java-index,Java Essentials,Java Programming...
# 16
>>so wat is \r....\r is return\n is new linein a txt format before a new line there must be a return character,if they do not exist both you only see a shape as you see a square, not a new line.ayberk cansever
ayberka at 2007-7-21 20:37:16 > top of Java-index,Java Essentials,Java Programming...