蛋疼的回车换行符

\r = 回车 = carriage return = CR = 13

\n = 换行 =  line feed = LF = 10

 

在Windows操作系统中,回车=将光标移动到一行的开始,换行=将光标移动到下一行。

在Linux系统中,换行=将光标移动到下一行的开始。

在Mac中,回车=将光标移动到下一行。

 

在Java的BufferedReader中,readLine方法其实是将\r,\n以及\r\n统统认为是一行的分隔符的:

    /**
     * Reads a line of text.  A line is considered to be terminated by any one
     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
     * followed immediately by a linefeed.
     *
     * @return     A String containing the contents of the line, not including
     *             any line-termination characters, or null if the end of the
     *             stream has been reached
     *
     * @exception  IOException  If an I/O error occurs
     */
    public String readLine() throws IOException {
        return readLine(false);
    }

 

而readLine的另一个重载,则允许指定是否忽略LF(回车)符号。

    /**
     * Reads a line of text.  A line is considered to be terminated by any one
     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
     * followed immediately by a linefeed.
     *
     * @param      ignoreLF  If true, the next '\n' will be skipped
     *
     * @return     A String containing the contents of the line, not including
     *             any line-termination characters, or null if the end of the
     *             stream has been reached
     * 
     * @see        java.io.LineNumberReader#readLine()
     *
     * @exception  IOException  If an I/O error occurs
     */
    String readLine(boolean ignoreLF) throws IOException {

 

不同的编辑器对回车换行符的支持也不同。

其中Notepad++是都支持,跟Java默认是一样的。

np

在VIM中,恪守了Linux里的规则,回车被显示成一个^M,换行则是换行。

vim

 

这不是纯蛋疼嘛。。。。。。。。。。。。。。。。。。。统一一下不就得了嘛。

转载于:https://www.cnblogs.com/deepnighttwo/archive/2011/07/01/2095877.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值