Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-20-2007, 10:07 PM
Super Moderator
 
Join Date: Apr 2007
Posts: 30
johnt is on a distinguished road
New line or Carriage Return through FileWriter
Hello,

I am using a java.io.FileWriter object to write some stuff to a given File object at runtime.

Everything works except I can't figure how to create new lines in the resulting file. All I am wirting in it appears stuck together, even if my String contain \n or \r characters.

I use java.io.FileWriter.write(String s) method.

Thanks for any help!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-20-2007, 10:10 PM
Member
 
Join Date: May 2007
Posts: 11
Hasan is on a distinguished road
Hi John,

You can wrap the FileWriter with a PrintWriter, and use println to write "lines" of text according to the platform it is running on.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-20-2007, 10:13 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hi John,

You can use Hasan's way.

But note that if you are on Windows, you need \r\n, both in that order. You can use the line.separator system property to get the proper separator in a generic way. That's what PrintWriter does internally.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading in data from file line by line bluekswing New To Java 1 10-02-2007 01:19 AM
if..else..return mqdias New To Java 1 08-10-2007 05:20 PM
Return value of method cachi New To Java 1 08-01-2007 09:23 AM
Using int/int, 7/5 would return 1 zoe New To Java 1 07-25-2007 09:45 PM
The return type Marcus New To Java 1 07-05-2007 07:28 AM


All times are GMT +3. The time now is 05:38 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org