Combining contents of files by reading them in a human ordering
NewLine

The newline at the end is correct... at least according to your code.

Files.lines(...) ignores the last line of input files if it has no characters. This is a standard system to have for most operating systems (the last character in a text file is a newline).

Your code is perpetuating this process, and it always adds a newline after each line printed.

Thus, your file always ends up with a newline at the end. This is a good thing.

Exceptions

Java Lambdas cannot contain expressions that throw caught exceptions. This is a weakness. The weakness is so sever that as part of Java8, there is the new Exception UncheckedIOException so that IO-based operations can throw an unchecked exception.

The easiest way to use it is to change your catch blocks to:

private Stream&lt;String&gt; wrappedLines(final Path path) {
    try {
        return Files.lines(path);
    } catch (IOException ioe) {
        throw new UncheckedIOException(ioe);
    }
}


The alternative is to wrap the exception inside the lambda with:

    try (BufferedWriter writer = Files.newBufferedWriter(directory.resolve("masterjob.script"))) {
        Files.list(directory)
                .filter(path -&gt; Files.isRegularFile(path))
                .filter(path -&gt; path.getFileName().toString().matches("job\\d+.script"))
                .sorted(Comparator.comparingInt(this::pathToInt))
                .flatMap(try { this::wrappedLines } catch(IOException ioe) {throw new UncheckedIOException(ioe)})
                .forEach(string -&gt; try {wrappedWrite(writer, string)} catch(IOException ioe) {throw new UncheckedIOException(ioe)});
    }


General

The Java8 side of this otherwise looks OK, and works fine for me too.