Here you can find the source of readFile(String p_filename)
Parameter | Description |
---|---|
p_filename | String |
Parameter | Description |
---|---|
IOException | an exception |
FileNotFoundException | an exception |
public static String readFile(String p_filename) throws IOException, FileNotFoundException
//package com.java2s; import java.io.*; public class Main { /**/*from w ww. j a va2s .com*/ * Read the content of a TEXT file * * @param p_filename String * @return String * @throws IOException * @throws FileNotFoundException */ public static String readFile(String p_filename) throws IOException, FileNotFoundException { int len = (int) (new File(p_filename)).length(); StringBuffer buf = new StringBuffer(len); BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(p_filename))); try { do { String data = r.readLine(); if (data == null) { break; } buf.append(data); buf.append('\n'); } while (true); } finally { r.close(); } return buf.toString(); } }