As dimo414 said, first declare a new functional interface
@FunctionalInterface public interface CheckedFunction<U, V> { public V apply(U u) throws Exception;IOException; } Then I'll go one step further by refactoring the lambda expression into the following:
CheckedFunction<String, String> lambda = path -> { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.lines().collect(Collectors.joining()); } }; The try-with-resources takes care of closing the BufferedRead in any case and using the conciseness of the stream API to concatenate all the lines.
Going a second step further, you don't even need to bother with BufferedReader anymore if you use Files ! This can be taken down to the following lambda:
CheckedFunction<String, String> lambda = path -> Files.lines(Paths.get(path)).collect(Collectors.joining());