String fileContents = readFile() for (String line : fileContents.split("\\r\\n|\\n")) { // Do whatever you want with the line System.out.println(line); }This works with Linux, Windows and Mac (Unix) line endings.
Programming Tips - Java: Nice way to split a String into lines
Date: 2012apr10
Language: Java
Q. Java: Nice way to split a String into lines
A. Use the split() method like this: