469,366 Members | 2,205 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Write new line in java into a text file

dmjpro
2,476 2GB
Recently I wokring on JAVA in windows platform.
I was able to write new line character in WINDOWS into a text file.

Expand|Select|Wrap|Line Numbers
  1. FileWriter.write("\r\n");
  2.  
but is it valid for all OS family.
I think it is not . ..so frnds is there any api that JAVA takes responsibility to write this according to native OS.
We need to take haedache to d this.
Is there any?

Pls help me.

Kind regards,
Dmjpro.
Aug 5 '07 #1
7 53952
JosAH
11,448 Expert 8TB
Recently I wokring on JAVA in windows platform.
I was able to write new line character in WINDOWS into a text file.

Expand|Select|Wrap|Line Numbers
  1. FileWriter.write("\r\n");
  2.  
but is it valid for all OS family.
Didn't you know the answer by now? Have a look at the API documentation for
the System.getProperties() method and see for yourself.

kind regards,

Jos
Aug 5 '07 #2
dmjpro
2,476 2GB
Didn't you know the answer by now? Have a look at the API documentation for
the System.getProperties() method and see for yourself.

kind regards,

Jos

u mean i ll get OS name from System.getProperties() then i ll decide what to do or u mean to something else.

pls help.

Kind regards,
Dmjpro.
Aug 6 '07 #3
JosAH
11,448 Expert 8TB
u mean i ll get OS name from System.getProperties() then i ll decide what to do or u mean to something else.

pls help.

Kind regards,
Dmjpro.
If you had read throught the available properties names I'm sure you would have
found the "line.separator" property and its value.

kind regards,

Jos
Aug 6 '07 #4
dmjpro
2,476 2GB
If you had read throught the available properties names I'm sure you would have
found the "line.separator" property and its value.

kind regards,

Jos

It is the environment variable of any OS if i m not wrong.
But when i did in C or C++ (DOS based) then only writing put('\n') it worked well.
It is poosible in DOS and in WINDOWS "\r\n" is required.
Am i right?

Pls help.

KInd regards,
Dmjpro.
Aug 6 '07 #5
JosAH
11,448 Expert 8TB
It is the environment variable of any OS if i m not wrong.
But when i did in C or C++ (DOS based) then only writing put('\n') it worked well.
It is poosible in DOS and in WINDOWS "\r\n" is required.
Am i right?

Pls help.

KInd regards,
Dmjpro.
The value of the line.separator is simply the end-of-line sequence on that
particular platform. The println() methods of the PrintStream and PrintWriter
classes use that variable value. If you want to print an end-of-line sequence
yourself you have to use that value too.

kind regards,

Jos
Aug 6 '07 #6
dmjpro
2,476 2GB
The value of the line.separator is simply the end-of-line sequence on that
particular platform. The println() methods of the PrintStream and PrintWriter
classes use that variable value. If you want to print an end-of-line sequence
yourself you have to use that value too.

kind regards,

Jos
Thanks a lot.
Today morning I did and suceeded.
Thanks a lot again.

Kind regards,
Dmjpro.
Aug 7 '07 #7
Thanks, i was trying for long to write a new line to a text file, but in vain, FileWriter.write("\r\n"); works fine!
Oct 10 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by burdeen | last post: by
3 posts views Thread by NewToPHP | last post: by
4 posts views Thread by Keith G Hicks | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.