gpt4 book ai didi

java - bufferedReader 中的读取行

转载 作者:搜寻专家 更新时间:2023-10-31 08:09:17 24 4
gpt4 key购买 nike

来自javadoc

public String readLine()
throws IOException

Read 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.

我有以下类型的文字:

Now the earth was formless and empty.  Darkness was on the surface
of the deep. God's Spirit was hovering over the surface
of the waters.

我读的行是:

 while(buffer.readline() != null){
}

但是,问题是它正在考虑换行之前的字符串行。但是我想考虑字符串以 . 结尾的行。我该怎么做?

最佳答案

您可以使用 Scanner并使用 useDelimiter(Pattern) 设置您自己的分隔符.

请注意,输入分隔符是 regex , 所以你需要提供正则表达式 \. (你需要打破正则表达式中字符 . 的特殊含义)

关于java - bufferedReader 中的读取行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10374191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com