Java InputStreamReader Read readFile(InputStream inputStream)

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

Description

read File

License

Apache License

Declaration

public static void readFile(InputStream inputStream) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void readFile(InputStream inputStream) throws IOException {
        InputStreamReader in = new InputStreamReader(inputStream);
        BufferedReader reader = new BufferedReader(in);
        String line;/*from  w  ww  . j  a v  a2 s  . c om*/
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        reader.close();
    }

    public static String readFile(File file, String encoding) {
        StringBuffer buffer = new StringBuffer();
        try {
            FileInputStream inputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, encoding);
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while ((tempString = reader.readLine()) != null) {
                buffer.append(tempString + "\n");
            }
            reader.close();
        } catch (Exception e) {
        }
        return buffer.toString();
    }

    public static String readFile(String filename, String encoding) {
        return readFile(new File(filename), encoding);
    }

    public static String readFile(File file) {
        StringBuffer buffer = new StringBuffer();
        try {
            FileInputStream inputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while ((tempString = reader.readLine()) != null) {
                buffer.append(tempString + "\n");
            }
            reader.close();
        } catch (Exception e) {
        }
        return buffer.toString();
    }

    public static String readFile(String filename) {
        return readFile(new File(filename));
    }
}

Related

  1. readFile(IFile file)
  2. readFile(IFile theFile)
  3. readFile(InputStream aStream)
  4. readFile(InputStream in)
  5. readFile(InputStream in)
  6. readFile(InputStream inputStream)
  7. readFile(InputStream inputStream)
  8. readFile(InputStream is)
  9. readFile(InputStream location)