read line by line keeping \n in java code example
Example: java read next line
Scanner scanner = new Scanner(new File("filename"));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// process the line
}
Scanner scanner = new Scanner(new File("filename"));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// process the line
}