Using Java 8, what is the most preferred and concise way of printing all the lines in a file?

前端 未结 3 1439
醉酒成梦
醉酒成梦 2020-12-15 23:17

What is the most preferred and concise way to print all the lines in a file using the new Java 8?

The output must be a copy of the file, line for line as in:

3条回答
  •  轮回少年
    2020-12-16 00:04

    Here is a simple solution:

    System.out.println( new String(Files.readAllBytes(Paths.get("sample.java"))) );
    

提交回复
热议问题