Results 1 to 3 of 3
  1. #1
    johnt is offline Super Moderator
    Join Date
    Apr 2007
    Posts
    30
    Rep Power
    0

    Default 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!

  2. #2
    Hasan is offline Member
    Join Date
    May 2007
    Posts
    11
    Rep Power
    0

    Default

    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.

  3. #3
    levent Guest

    Default

    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.

Similar Threads

  1. Using int/int, 7/5 would return 1
    By zoe in forum New To Java
    Replies: 2
    Last Post: 12-02-2008, 11:25 AM
  2. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  3. if..else..return
    By mqdias in forum New To Java
    Replies: 1
    Last Post: 08-10-2007, 04:20 PM
  4. Return value of method
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 08:23 AM
  5. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 06:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •