Android File Read readFromFile(String filename)

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

Description

read From File

License

Open Source License

Parameter

Parameter Description
data a parameter

Declaration

private static String readFromFile(String filename) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class Main {
    /**/*from   w w  w .  j  a v  a2  s  .co m*/
     * 
     * @param data
     */
    private static String readFromFile(String filename) {
        File file = new File(filename);
        byte b[] = null;
        try {
            if (file.exists()) {
                b = new byte[(int) file.length()];
                InputStream fi = new FileInputStream(file);
                fi.read(b);
                fi.close();
            }
        } catch (Exception e) {
            return null;
        }

        if (null != b) {
            return new String(b);
        }
        return null;
    }
}

Related

  1. readFile(String filepath)
  2. readFileAsString(String filePath)
  3. readFileToByte(File file)
  4. readFileToString(String fileName)
  5. readFileToString(String pathToFile)
  6. readInstallationFile(File installation)
  7. readStringFromFile(File file)
  8. readTemplate(String filePath)
  9. readTextFile(File file)