Android Text File Read readFile(String filename)

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

Description

Read a file into a string

Parameter

Parameter Description
filename a parameter

Exception

Parameter Description

Declaration

public static String readFile(String filename)
        throws java.io.IOException 

Method Source Code

//package com.java2s;
import java.io.*;

public class Main {
    /**/*w w w  . j a  va2 s .  com*/
     * Read a file into a string
     *
     * @param filename
     * @return
     * @throws java.io.IOException
     */
    public static String readFile(String filename)
            throws java.io.IOException {
        StringBuffer fileData = new StringBuffer(1000);
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
            buf = new char[1024];
        }
        reader.close();
        return fileData.toString();
    }
}

Related

  1. readFile(File file, String encoding)
  2. readFile(File in)
  3. readFile(String fileName)
  4. readFile(String fileName)
  5. readFile(String filePath)
  6. readFile(String path)
  7. readFileAsString(File file)
  8. readFileAsString(File file, String charset)
  9. readFileAsString(String filename)