Java InputStreamReader Read readFile(File f)

Here you can find the source of readFile(File f)

Description

read File

License

Open Source License

Declaration

public static String readFile(File f) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source 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 readFile(File f) throws IOException {
        return read(new FileInputStream(f));
    }//from   ww w.  j  a v  a 2s  . c  o m

    public static String read(InputStream in) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(in));
        StringBuilder b = new StringBuilder();

        String line = null;
        while ((line = r.readLine()) != null) {
            b.append(line);
            b.append('\n');
        }

        return b.toString();
    }
}

Related

  1. loadAsText(InputStream in, String encoding, int bufferSize)
  2. readFile(Class cl, String filename)
  3. readFile(Class cls, String filename)
  4. readFile(ClassLoader classloader, String filename)
  5. readFile(File f)
  6. readFile(File f)
  7. readFile(File f)
  8. readFile(File f)
  9. readFile(File file)