Here you can find the source of readFile(String fileName)
public static char[] readFile(String fileName) throws IOException
//package com.java2s; /*/*from w w w. ja v a 2 s . c o m*/ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static char[] readFile(String fileName) throws IOException { return readFile(fileName, null); } public static char[] readFile(String fileName, String encoding) throws IOException { File f = new File(fileName); int size = (int) f.length(); InputStreamReader isr; FileInputStream fis = new FileInputStream(fileName); if (encoding != null) { isr = new InputStreamReader(fis, encoding); } else { isr = new InputStreamReader(fis); } char[] data = null; try { data = new char[size]; int n = isr.read(data); if (n < data.length) { data = Arrays.copyOf(data, n); } } finally { isr.close(); } return data; } }