Java FileReader Read readFile(File file)

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

Description

Read file contents as a string

License

Open Source License

Exception

Parameter Description
IOException an exception

Declaration

public static String readFile(File file) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    /**/*from   w w  w . j av a 2s .  c  o  m*/
     * Read file contents as a string
     * @throws IOException 
     */
    public static String readFile(File file) throws IOException {
        StringWriter s = new StringWriter();
        char[] buff = new char[1000];

        FileReader in = new FileReader(file);
        try {
            int read = 0;
            while ((read = in.read(buff)) >= 0) {
                s.write(buff, 0, read);
            }
        } finally {
            in.close();
        }

        return s.toString();
    }
}

Related

  1. readFile(File f)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)