I hava text file that contains some data. All paragraphs start with four spaces. My aim is to split this text into paragraphs.
First, I read the whole text using:
public String parseToString(String filePath) throws IOException{
return new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
}
Then I use this code to split the string:
private static final String PARAGRAPH_SPLIT_REGEX = "(^\\s{4})";
public void parseText(String text) {
String[] paragraphs = text.split(PARAGRAPH_SPLIT_REGEX);
for (int i = 0; i < paragraphs.length; i++) {
System.out.println("Paragraph: " + paragraphs[i]);
}
}
My input file is:
Hello, World!
Hello, World!
And the output is:
Paragraph:
Paragraph: Hello, World!!!
Hello, World!!!
What am i doing wrong?