Java InputStreamReader Read readFiles(String[] files, String encoding)

Here you can find the source of readFiles(String[] files, String encoding)

Description

read Files

License

Apache License

Declaration

public static String readFiles(String[] files, String encoding) 

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 String readFiles(File[] files, String encoding) {
        StringBuffer buffer = new StringBuffer();
        for (File file : files) {
            buffer.append(readFile(file, encoding));
        }//from   w w w  .  ja  v  a 2s  . c  om
        return buffer.toString();
    }

    public static String readFiles(String[] files, String encoding) {
        StringBuffer buffer = new StringBuffer();
        for (String pathname : files) {
            File file = new File(pathname);
            buffer.append(readFile(file, encoding));
        }
        return buffer.toString();
    }

    public static void readFile(InputStream inputStream) throws IOException {
        InputStreamReader in = new InputStreamReader(inputStream);
        BufferedReader reader = new BufferedReader(in);
        String line;
        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. readFileIntoLinesOfLongs(File file)
  2. readFileLineByLine(final File filePath)
  3. readFileList(File file)
  4. readFileOneLine(String filename, String keyInLine)
  5. readFileOrResource(String source)
  6. readFileSB(File f)
  7. readFileToLines(File file)
  8. readFileToList(String fileName, String codeing)
  9. readFileToSet(String filePath, String fileEncoding)