471,863 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

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 54091
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
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.