Java InputStreamReader Read readFile(String filename)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String filename) 

Method Source Code


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

public class Main {
    public static String readFile(String filename) {
        File in = new File(filename);
        try {//from   w w w .  j av a2 s.c o  m
            Reader fr = new InputStreamReader(new FileInputStream(in), "UTF-8");
            char[] cbuf = new char[(int) in.length()];
            try {
                fr.read(cbuf);
                return String.valueOf(cbuf);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. readFile(String file)
  2. readFile(String file, String charset)
  3. readFile(String file, String lineBreak)
  4. readFile(String fileFullPath)
  5. readFile(String fileName)
  6. readFile(String fileName)
  7. readFile(String filename)
  8. readFile(String filename)
  9. readFile(String fileName)