What is the meaning \r carriage return and \f form feed in Java?

前端 未结 4 1255
再見小時候
再見小時候 2020-12-24 15:04

What is the meaning of \\r carriage return and /f form feed in Java? Can anyone give a small example of when we have to use these types of symbols?

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 16:00

    You rarely use either of them (in isolation) in modern applications.

    \r (carriage return) is what it sounds like if you're familiar with old-fashioned manual typewriters: It moves the "carriage" (the roll the paper is fed through) back to the beginning of the line. On a terminal (or similar), it moves the output point back to the beginning of the line, without moving down a line (usually).

    \f is (as you said) a formfeed, it tells old-fashioned printers to start a new page. In computer documents, it's sometimes used to indicate a page break.

    Rounding things out, there's also line feed (aka "newline"): \n. This means "move down a line." In some terminals, it just moves down a line without doing a carriage return; on others, it does both.

    \n (LF, newline) is the standard text file line break on *nix and derived operating systems. \r\n (CRLF) is the standard text file line break on DOS and Windows. Back in the day, \r (on its own) was the standard line break in text files on the Mac, prior to Mac OS X (which is *nix-derived).

提交回复
热议问题