Java InputStreamReader Read readFile(InputStream in)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(InputStream in) throws IOException 

Method Source Code


//package com.java2s;
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 String readFile(InputStream in) throws IOException {
        StringBuffer sb = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        try {//from w w  w. j  av  a  2s. c om
            readFile(reader, sb);
        } finally {
            reader.close();
        }
        return sb.toString();
    }

    public static String readFile(File f) throws IOException {
        StringBuffer sb = new StringBuffer();
        InputStream in = new FileInputStream(f);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        try {
            readFile(reader, sb);
        } finally {
            reader.close();
        }
        return sb.toString();
    }

    public static void readFile(BufferedReader reader, StringBuffer sb) throws IOException {
        String line = null;
        do {
            line = reader.readLine();
            if (line != null) {
                sb.append(line);
                sb.append("\n");
            }
        } while (line != null);
    }
}

Related

  1. readFile(final String aFileName)
  2. readFile(final String path)
  3. readFile(IFile file)
  4. readFile(IFile theFile)
  5. readFile(InputStream aStream)
  6. readFile(InputStream in)
  7. readFile(InputStream inputStream)
  8. readFile(InputStream inputStream)
  9. readFile(InputStream inputStream)