473,420 Members | 1,579 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,420 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 54373
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.