Solved

How to put Enter key character (\n) in text file (Urgent)

Posted on 2001-09-01
6
199 Views
Last Modified: 2008-03-06
i am storing different Tele phone nos in text file.
i want to store each no. on next line.
how i move my file pointer to next line or put enter key often \n.

Regards,

Macha
0
Comment
Question by:macha060500
6 Comments
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 30 total points
ID: 6448020
If using a FileWriter, you can write a newline character directly a in:

    FileWriter out = ...
    out.write("\n");

It would better, though, to use the platform-specific line separator sequence. You can get this from System properties:

    String sep = System.getProperty("line.separator");
    out.write(sep);

If you wrap your FileWriter with a BufferedWriter -- which is a good performance idea anyway -- then you can use the BufferedWriter's newLine method which does the above.

    FileWriter fw = ...
    BufferedWriter out = new BufferedWriter(fw);
    out.newLine();

Best regards,
Jim Cakalic
0
 
LVL 92

Expert Comment

by:objects
ID: 6448376
Use a PrintWriter to print to your file and use the method println() which inserts a platform independant newline.
0
 
LVL 5

Expert Comment

by:vemul
ID: 7773232
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- split points between jim_cakalic and objects

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 7773261
OK.
0
 

Expert Comment

by:SpideyMod
ID: 7861447
Answered by jim_cakalic (first in with answer and points too low for split)

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 7870177
Thanks. :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now