Solved

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

Posted on 2001-09-01
6
196 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

21 Experts available now in Live!

Get 1:1 Help Now