Is there an equivalent of BufferedReader.readLine() that lets me pick what my end of line characters are?

六月ゝ 毕业季﹏ 提交于 2019-12-05 01:01:13
Greg Noe

Try using the Scanner class:

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

Depending on what the use case for which you need the BufferedReader, you can maybe change over to using the Scanner class, which is able to read text from different sources (files, streams), and has a direct method th specify the delimiting pattern. See http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html#useDelimiter(java.lang.String)

I don't know of any standard API that would acomplish this.

It's possible to simple read in the WHOLE file into a String and then split it at your desired ending character.

for(String line: testFile.split("\r\n")){
...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!