Write new line in java into a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Write new line in java into a text file

    Recently I wokring on JAVA in windows platform.
    I was able to write new line character in WINDOWS into a text file.

    [code=java]
    FileWriter.writ e("\r\n");
    [/code]

    but is it valid for all OS family.
    I think it is not . ..so frnds is there any api that JAVA takes responsibility to write this according to native OS.
    We need to take haedache to d this.
    Is there any?

    Pls help me.

    Kind regards,
    Dmjpro.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by dmjpro
    Recently I wokring on JAVA in windows platform.
    I was able to write new line character in WINDOWS into a text file.

    [code=java]
    FileWriter.writ e("\r\n");
    [/code]

    but is it valid for all OS family.
    Didn't you know the answer by now? Have a look at the API documentation for
    the System.getPrope rties() method and see for yourself.

    kind regards,

    Jos

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by JosAH
      Didn't you know the answer by now? Have a look at the API documentation for
      the System.getPrope rties() method and see for yourself.

      kind regards,

      Jos

      u mean i ll get OS name from System.getPrope rties() then i ll decide what to do or u mean to something else.

      pls help.

      Kind regards,
      Dmjpro.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by dmjpro
        u mean i ll get OS name from System.getPrope rties() then i ll decide what to do or u mean to something else.

        pls help.

        Kind regards,
        Dmjpro.
        If you had read throught the available properties names I'm sure you would have
        found the "line.separator " property and its value.

        kind regards,

        Jos

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by JosAH
          If you had read throught the available properties names I'm sure you would have
          found the "line.separator " property and its value.

          kind regards,

          Jos

          It is the environment variable of any OS if i m not wrong.
          But when i did in C or C++ (DOS based) then only writing put('\n') it worked well.
          It is poosible in DOS and in WINDOWS "\r\n" is required.
          Am i right?

          Pls help.

          KInd regards,
          Dmjpro.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by dmjpro
            It is the environment variable of any OS if i m not wrong.
            But when i did in C or C++ (DOS based) then only writing put('\n') it worked well.
            It is poosible in DOS and in WINDOWS "\r\n" is required.
            Am i right?

            Pls help.

            KInd regards,
            Dmjpro.
            The value of the line.separator is simply the end-of-line sequence on that
            particular platform. The println() methods of the PrintStream and PrintWriter
            classes use that variable value. If you want to print an end-of-line sequence
            yourself you have to use that value too.

            kind regards,

            Jos

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by JosAH
              The value of the line.separator is simply the end-of-line sequence on that
              particular platform. The println() methods of the PrintStream and PrintWriter
              classes use that variable value. If you want to print an end-of-line sequence
              yourself you have to use that value too.

              kind regards,

              Jos
              Thanks a lot.
              Today morning I did and suceeded.
              Thanks a lot again.

              Kind regards,
              Dmjpro.

              Comment

              • aatish

                #8
                Thanks, i was trying for long to write a new line to a text file, but in vain, FileWriter.writ e("\r\n"); works fine!

                Comment

                Working...