Android Text File Read readFile(File in)

Here you can find the source of readFile(File in)

Description

read File

Declaration

public static String readFile(File in) 

Method Source Code

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

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

import java.io.InputStream;

public class Main {
    public static String readFile(File in) {
        try {/*from  ww w  .  ja  va  2 s  .  c  o  m*/
            return readFile(new FileInputStream(in));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String readFile(InputStream input) {
        BufferedInputStream reader = null;
        String rt = null;
        try {
            byte[] buffer = new byte[input.available()];
            reader = new BufferedInputStream(input);
            reader.read(buffer);
            reader.close();
            input.close();
            rt = new String(buffer);
        } catch (Exception e) {
            e.printStackTrace();
            return rt;
        } finally {
            try {
                if (input != null)
                    input.close();
                if (reader != null)
                    reader.close();
            } catch (Exception e) {
            }
        }

        return rt;
    }
}

Related

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