欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

使用Apache commons的FileUtils类读取文本文件内容到字符串,,下面示例使用Apache

来源: javaer 分享于  点击 40607 次 点评:241

使用Apache commons的FileUtils类读取文本文件内容到字符串,,下面示例使用Apache


下面示例使用Apache commons的FileUtils类读取文本文件内容到字符串

package cn.outofmemory.examples;import org.apache.commons.io.FileUtils;import java.io.File;import java.io.IOException;/** * * @author byrx.net */public class Main {    public static void main(String[] args) {        File file = new File("myfile.txt");        try {            String content = FileUtils.readFileToString(file);            System.out.println("Contents of file: " + content);        } catch (IOException e) {            e.printStackTrace();        }    }}
相关栏目:

用户点评