I am reading a file using the scanner class.I want my EOL delimiter to be CR LF but there are some records in the file which have only LF hence my scanner is reading the LF and going to the next line. I want the scanner to go to the next line only when it encounters CR LF both.
Here is my snippet: (using double slashes in the regex also gives same result)
java.util.Scanner sMain = new java.util.Scanner(inputStream,encoding)
.useDelimiter(Pattern.compile("[\r\n]"));
while (sMain.hasNextLine()) {
// sysout line
}
So you want a delimiter which is
"[\r\n]"means one of \r or \n.The delimiter determines the separator between “words”. To break up the line you can use split(“~”) as follows.
prints