• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Writing a New Line in Java

QuantumSlip

Supreme [H]ardness
Joined
Feb 4, 2001
Messages
4,979
OK, for some reason I'm trying to write a new line or carriage return to a text file to start a new line, and neither one of them work. I've tried using raf.writeByte and raf.writeChar with \n and \r (ASCII 13, 10 respectively, and raf is of type RandomAccessFile), and it just ends up making a space instead. I tried appending \n to my string, but again it just makes a space. Anyone have any ideas on how to get this to work?

code:
raf.writeChar('\n'); //just makes a space
raf.writeChar('\r'); //just makes a space too

and so on with writeByte and writeBytes; putting it into a String doesn't help either.
 
assuming "raf" is a PrintWriter object (the only thing i know to write to text files), you can just do raf.println();
 
well raf is of class RandomAcessFile, so none of those worked. i did get it to work with creating a string called lineSeparator which contained System.getProperty("line.separator"); a friend of mind found that in some post on the java site. Maybe sun should standardize this or something... oh well
 
If my memory serves well (It rarely does...)

Under the windows platform, a new line is "\r\n".

Probably the System..getProperty("line.separator") returns the above String.
 
Back
Top