Android InputStream Read readFile(InputStream input)

Here you can find the source of readFile(InputStream input)

Description

read File

Declaration

public static String readFile(InputStream input) 

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   w  w w  .  j av  a  2 s.c  om*/
            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. ReadArrayOfStringPairs( FileInputStream stream)
  2. ReadInt(FileInputStream stream)
  3. ReadString(FileInputStream stream)
  4. readContents(InputStream input, String encoding)
  5. readFully(InputStream in)
  6. readInputStreamToString(InputStream input, String enCoding)
  7. writeToStream(InputStream in, OutputStream out, boolean closeOnExit)
  8. readStream(InputStream in)