Results 1 to 4 of 4
  1. #1
    vissu007 is offline Member
    Join Date
    Jun 2007
    Posts
    13
    Rep Power
    0

    Default Please help me out here

    consider the following program segment..

    FileWriter f=new FileWriter(args[0]);
    ............
    ..........
    f.write('\n');

    The above given segment is from one of my programs.whenever I use f.write('\n') to go to a new line in the output file,the function is printing a small square box in the file.But,I want it to move the control to a new line so that whatever character it writes in the file thereafter writes it in a new line.This is happening for all the escape sequences used.Can anybody give me a solution for this problem?Reply soon.Thanq....

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    "\n" is not a platform independent way of writing a new line to a file. Try using:

    Java Code:
    f.write(System.getProperty("line.separator"));
    Here are some relevant javadocs:

    BufferedWriter.html#newLine()
    System.html#getProperties()

  3. #3
    vissu007 is offline Member
    Join Date
    Jun 2007
    Posts
    13
    Rep Power
    0

    Default

    Thanks for the reply.What about using other escape sequences like '\b'(Whitespace)?

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    The problem is not escape sequences! They are same on all platforms. The problem is the new line for files! As far as i remember it was \r\n (Linux i guess) in one platform and \n (Windows i guess) in the other one.

Posting Permissions

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