difference between newLine() and carriage return(“\r”)

后端 未结 5 1919
失恋的感觉
失恋的感觉 2020-12-05 22:44

What is the difference between newLine() and carriage return (\"\\r\")? Which one is best to use?

File f = new File(strFileGenLoc);
BufferedWrit         


        
5条回答
  •  不知归路
    2020-12-05 23:08

    the major newLine(\n) and carriage return (\r) is :

    new line(\n) & carriage return (\r) both r escape sequence in java..

    new line(\n):

    when ever \n is found in executable statements,the JVM splits the line into 2 parts from where we placed \n (escape sequence).. example :

    println("Stackover\nflow");
    

    output:

    Stackover // here the line got split into 2 lines because of "\n"   
    flow
    

    carriage return (\r):

    the data or character placed after the \r get overtire with the previous characters present in the same line ...

    example :

    println("Stackover\rflow"); 
    output:
    flow  // here Statckover is overtired  because of "\r" 
    

提交回复
热议问题