• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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

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
macha060500
Asked:
macha060500
1 Solution
 
Jim CakalicSenior Developer/ArchitectCommented:
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
 
objectsCommented:
Use a PrintWriter to print to your file and use the method println() which inserts a platform independant newline.
0
 
vemulCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jim CakalicSenior Developer/ArchitectCommented:
OK.
0
 
SpideyModCommented:
Answered by jim_cakalic (first in with answer and points too low for split)

SpideyMod
Community Support Moderator @Experts Exchange
0
 
Jim CakalicSenior Developer/ArchitectCommented:
Thanks. :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now