The strings returned from the readAllLines()
method does not include the end of line character.
The readAllLines()
method recognizes the following line terminators:
import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; public class Main { public static void main(String[] args) { Charset cs = Charset.forName("US-ASCII"); Path source = Paths.get("Main.java"); try {/*from w w w. j a va 2 s .c o m*/ List<String> lines = Files.readAllLines(source, cs); for (String line : lines) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }