Java FileInputStream Read readFile(String filename)

Here you can find the source of readFile(String filename)

Description

read File

License

LGPL

Declaration

public static String readFile(String filename) throws FileNotFoundException 

Method Source Code

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

import java.io.*;

public class Main {
    public static String readFile(String filename) throws FileNotFoundException {
        FileInputStream in = new FileInputStream(filename);
        return readContents(in);
    }/* w w w  . j  a  v  a2s  . c  om*/

    public static String readContents(InputStream input) {
        StringBuilder sb = new StringBuilder();
        int ch;
        while (true) {
            try {
                ch = input.read();
                if (ch != -1)
                    sb.append((char) ch);
                else
                    break;
            } catch (IOException e) {
                break;
            }
        }
        return sb.toString();
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String fileName)
  3. readFile(String filename)
  4. readFile(String fileName)
  5. readFile(String filename)
  6. readFile(String filename)
  7. readFile(String fileName)
  8. readFile(String fileName)
  9. readFile(String filename)