Java InputStreamReader Read readFile(String p_filename)

Here you can find the source of readFile(String p_filename)

Description

Read the content of a TEXT file

License

Open Source License

Parameter

Parameter Description
p_filename String

Exception

Parameter Description
IOException an exception
FileNotFoundException an exception

Return

String

Declaration

public static String readFile(String p_filename) throws IOException, FileNotFoundException 

Method Source Code


//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();
    }
}

Related

  1. readFile(String filePath, String charsetName, long lineNow, long lineEnd)
  2. readFile(String input)
  3. readFile(String location)
  4. readFile(String name)
  5. readFile(String nomeFile)
  6. ReadFile(String Path)
  7. readFile(String path)
  8. readFile(String path)
  9. readFile(String path)