This is what I have been working so far for reading a text file,
Scanner file = new Scanner(new File("sample.txt")).useDelimiter(".");
ArrayList<String> arr = new ArrayList<>();
while (file.hasNextLine()) {
strList.add(file.nextLine());
}
file.close();
for (int i = 0; i < arr.size(); i++) {
System.out.println(arr.get(i));
}
and my text file looks like this,
I love you. You
love me. He loves
her. She loves him.
I want a result of the code like,
I love you
You love me
He loves her
She loves him
But the result is same as the text file itself. Isn't that "useDelimiter(".")" suppose to separate the text file with period(".")?
I've also tried to use hasNext() and next() instead of hasNextLine() and nextLine(), but it prints out empty 30ish new lines.