473,549 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write new line in java into a text file

dmjpro
2,476 Top Contributor
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 54384
JosAH
11,448 Recognized Expert MVP
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.getPrope rties() method and see for yourself.

kind regards,

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

kind regards,

Jos

u mean i ll get OS name from System.getPrope rties() 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 Recognized Expert MVP
u mean i ll get OS name from System.getPrope rties() 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 Top Contributor
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 Recognized Expert MVP
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 Top Contributor
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.writ e("\r\n"); works fine!
Oct 10 '10 #8

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

Similar topics

3
8579
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 marks '?'. Please, How do i accomplish this? I've been searching for a solution for weeks... why has nobody even asked this question? shouldn't it be...
3
2378
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
16928
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
5545
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 line like user. i'm sorry for my english :D if user exist delete a line of the user and insert new line. if not exist insert new line. possibility...
2
1614
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 of Recipe" dfgsdgfsdfgsdgf dgfsdfgdfgsdfsdfgsdfg "Recipe" edsadfasdfasdfasdfasdf sadfasdf5twtgfvdfgdfgdsfg rgg5345454ygdfgdgfdsgdsf
6
248930
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 System; using System.IO; using System.Diagnostics;
4
2289
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 another file, so far i've only been able to read the whole text from one file and write it to another file,can anyone please help me solve my...
4
4519
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 (MISCA F.572 of 2001) BWHC 2 "2002_1.rtf" (7 June 2002) Olebeng v The State (C A No. F104 of 2001) BWHC 1 "2003_1.rtf" (1 January 2003) Sebogodi v...
4
3321
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 whatever is in the textfile at that time. I open the file, and then I go to the end, and write the stuff. I came up with the following code: ...
4
3385
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 database. What I need help with is on how to locate a specific line in the file, change it and then save the updated text file. Can anyone help me out or...
0
7541
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5385
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5107
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.