Solved

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

Posted on 2001-09-01
6
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

696 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