my file contains this string:
a
b
c
now I want to read it and split it with empty line so I have this:
text.split("\n\n"); where text is output of file
problem is that this doesnt work. When I convert new line to byte I see that “\n\n” is represented as 10 10 but new line in my file is represented by 10 13 10 13. So how I can split my file ?
So you need to try
string.split("\n\r")in your case.Edit
If you want to split by empty line, try
\n\r\n\r. Or you can use.readLine()to read your file, and skip all empty lines.Are you sure it’s
10 13 10 13? It always should be13 10…And, you should not depend on
line.separatortoo much. Because if you are processing some files from *nix platform, it’s\n, vice versa. And even on Windows, some editors use\nas the new line character. So I suggest you to use some high level methods or usestring.replaceAll("\r\n", "\n")to normalize your input.