Split text file into Strings on empty line

后端 未结 6 1427
温柔的废话
温柔的废话 2021-02-15 16:12

I want to read a local txt file and read the text in this file. After that i want to split this whole text into Strings like in the example below .

Example : Lets say

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-15 16:27

    It may depend on how the file is encoded, so I would likely do the following:

    String.split("(\\n\\r|\\n|\\r){2}");
    

    Some text files encode newlines as "\n\r" while others may be simply "\n". Two new lines in a row means you have an empty line.

提交回复
热议问题