使用Apache commons的FileUtils类读取文本文件内容到字符串,,下面示例使用Apache
分享于 点击 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(); } }}
用户点评