gpt4 book ai didi

java - 读取文件时可以使用 EOF 或 EOL 以外的其他分隔符吗

转载 作者:行者123 更新时间:2023-12-02 07:55:35 25 4
gpt4 key购买 nike

我想解析一个文件并使用 2 个“换行符”(\n) 作为分隔符而不是 EOL,并将其添加到字符串对象中。

这是算法 -

1. While end of file is not reached
2. Read a file until you hit 2 \n's or eof is reached
put that contents as a string to a List object.
3. go to 1.

最佳答案

您可以使用Scanner.useDelimiter()方法。

public Scanner useDelimiter(String pattern)

Sets this scanner's delimiting pattern to a pattern constructed from the specified String.

According to JLS新行是

LineTerminator:

the ASCII LF character, also known as "newline"

the ASCII CR character, also known as "return"

the ASCII CR character followed by the ASCII LF character

关于java - 读取文件时可以使用 EOF 或 EOL 以外的其他分隔符吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700092/

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