package sample; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Collectors; import java.util.stream.Stream; public class ReadFileToString { public static void main(String[] args) { try{ Path path = Paths.get("exec_select.sql"); Stream<String> lines = Files.lines(path); String content = lines.collect(Collectors.joining(System.lineSeparator())); System.out.println(content); lines.close(); }catch(IOException e){ e.printStackTrace(); System.exit(1); } System.exit(0); } }