read complete file without using loop in java

后端 未结 5 1893
长情又很酷
长情又很酷 2020-11-28 05:05

Possible Duplicate:
How to create a Java String from the contents of a file
Whole text file to a String in Java

5条回答
  •  暖寄归人
    2020-11-28 05:32

    Java 7 one line solution

    List lines = Files.readAllLines(Paths.get("file"), StandardCharsets.UTF_8);
    

    or

     String text = new String(Files.readAllBytes(Paths.get("file")), StandardCharsets.UTF_8);
    

提交回复
热议问题