是否有相当于BufferedReader.readLine()的东西让我选择行尾字符的结尾? [英] Is there an equivalent of BufferedReader.readLine() that lets me pick what my end of line characters are?

查看:121
本文介绍了是否有相当于BufferedReader.readLine()的东西让我选择行尾字符的结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BufferedReader的Javadoc .readLine()说:


任何一个换行符都会认为该行被终止('\ n'),
a回车('\ r'),或者一个回车后紧接着换行。

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.

我需要比这更好的控制(例如,我希望能够指定行尾为\\\\ n),因此\ n本身不会终止该行)。

I need slightly better control than this (e.g. I would like to be able to specify that an end of line is "\r\n", so that an "\n" by itself does not terminate the line).

是否有任何JDK或库函数执行此操作?

Is there any JDK or library function which does this?

推荐答案

尝试使用扫描仪课程:

String line = Scanner(file).useDelimiter("\r\n").next();

这篇关于是否有相当于BufferedReader.readLine()的东西让我选择行尾字符的结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆