read complete file without using loop in java

后端 未结 5 1874
长情又很酷
长情又很酷 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:35

    If you are using Java 5/6, you can use Apache Commons IO for read file to string. The class org.apache.commons.io.FileUtils contais several method for read files.

    e.g. using the method FileUtils#readFileToString:

    File file = new File("abc.txt");
    String content = FileUtils.readFileToString(file);
    

提交回复
热议问题