473,379 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 54372
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

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

Similar topics

3
by: burdeen | last post by:
I can't find any way of writing a unicode, or UTF-8 format text file. Right now i have a Unicode string that i write to the text file and the unicode characters are replaced with ANSI question...
3
by: NewToPHP | last post by:
I am COMPLETELY NEW TO PHP San someone supply me with a PHP script to read and write to a text file on the server Also any suggestion on a free PHP editor?
14
by: Niron kag | last post by:
Hello ! With c# , I want to write to a text file in a specific font and color. Any ideas ? Thanks...
4
by: jeepers | last post by:
Hi all, my problem is delete a line in a text file. the file contain -n line with user, userCode. i want to replace the line with user is egual at user, and/or insert new line but delete the...
2
by: Quentin | last post by:
Any code on how to start write to a new file would be appreciated. In the example below: How would I start the write to a file on the word "Recipe" and then write every line beneath it until "End...
6
Atran
by: Atran | last post by:
Hello: In this article: You will learn to Write or Read A Text File. Let's Begin: First Create a new project (ConsoleApp or WinApp). And Make sure your program uses these namespaces: using...
4
by: someone28485 | last post by:
hi,i need 2 write code in C#.Net to read a text file with text as 22.13 21.65 25.16 31.22 and so on, i need 2 read this text and then take mean of the 4 values and write that mean result in...
4
by: Johnymap | last post by:
Hi everyone. The text file i am using has the following format: "2001_1.rtf" (1 January 2001) Ookame v Tombale (CCF No. 203 of 2001) BWHC 1 "2001_2.rtf" (1 January 2001) Kgaimena v Leoifo...
4
by: mvvdsteen | last post by:
Hello all, I'm quite new to c++. I made a small program that will help me analyse wind tunnel data. But now I want this program to write to a text file. This works just fine, except it discards...
4
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.