Android File Read getFileContent(File file)

Here you can find the source of getFileContent(File file)

Description

get File Content

Declaration

public static String getFileContent(File file) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    public static String getFileContent(File file) {
        //setPermissions(file.getAbsolutePath());
        FileInputStream fin = null;
        //Log.d("FILE", file.getAbsolutePath());
        byte fileContent[] = null;
        try {/*from w  w w . ja  v  a 2 s  .  c  om*/
            fin = new FileInputStream(file);
            fileContent = new byte[(int) file.length()];
            fin.read(fileContent);
        } catch (FileNotFoundException e) {
        } catch (IOException ioe) {
            //System.out.println("Exception while reading file " + ioe);
        } finally {
            try {
                if (fin != null) {
                    fin.close();
                    fin = null;
                }
            } catch (IOException ioe) {
                //System.out.println("Error while closing stream: " + ioe);
            }
        }
        return new String(fileContent).split("\n")[0];
    }
}

Related

  1. readInstallationFile(File installation)
  2. readStringFromFile(File file)
  3. readTemplate(String filePath)
  4. readTextFile(File file)
  5. loadFile(String str)
  6. LoadFile(String fileName, Resources resources)
  7. readFileToByteArray(String pathToFile)