Here you can find the source of readFile(String fileName, String characterEncoding)
public static String readFile(String fileName, String characterEncoding) throws UnsupportedEncodingException, FileNotFoundException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 eBay Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from www . j a v a2 s. c o m*/ * eBay Inc. - initial API and implementation *******************************************************************************/ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class Main { public static String readFile(String fileName, String characterEncoding) throws UnsupportedEncodingException, FileNotFoundException, IOException { FileInputStream fis; InputStreamReader isr; StringBuilder sb = new StringBuilder(75000); char[] buf = new char[4096]; int numRead; fis = new FileInputStream(fileName); isr = new InputStreamReader(fis, characterEncoding); do { numRead = isr.read(buf, 0, buf.length); if (numRead > 0) { sb.append(buf, 0, numRead); } } while (numRead >= 0); isr.close(); fis.close(); return sb.toString(); } }