Java FileReader Read readFile(Reader reader)

Here you can find the source of readFile(Reader reader)

Description

read File

License

Open Source License

Declaration

public static String readFile(Reader reader) throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.io.Reader;

public class Main {
    public static String readFile(Reader reader) throws IOException {
        return readerToString(reader);
    }/*from w w w .  j a va  2 s . c  o  m*/

    public static String readFile(File f) throws IOException {
        FileReader reader = new FileReader(f);
        return readFile(reader);
    }

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

    public static String readerToString(Reader is) throws IOException {
        StringBuffer sb = new StringBuffer();
        char[] b = new char[4 * 1024];
        int n = is.read(b);

        // Read a block. If it gets any chars, append them.
        while (n > 0) {
            sb.append(b, 0, n);
            n = is.read(b);
        }

        // Only construct the String object once, here.
        String s = sb.toString();
        // log.debug(this, "file contents:\n\t" + s);

        return (s);
    }
}

Related

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