Here you can find the source of readTextFile(File file, String charsetName)
public static String readTextFile(File file, String charsetName) throws IOException
//package com.java2s; /*/*from w w w .j a va2 s . c om*/ * FileUtil.java * * Copyright (c) 1998 - 2005 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium Business Suite Anywhere System. * */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { /** * The default size of the copy buffer. */ public static final int DEFAULT_BUFFER_SIZE = 8192; public static String readTextFile(String fullPathFilename) throws IOException { return readTextFile(new File(fullPathFilename)); } public static String readTextFile(String fullPathFilename, String charsetName) throws IOException { return readTextFile(new File(fullPathFilename), charsetName); } public static String readTextFile(File file) throws IOException { return readTextFile(file, null); } public static String readTextFile(File file, String charsetName) throws IOException { StringBuffer sb = new StringBuffer(DEFAULT_BUFFER_SIZE); FileInputStream fis = new FileInputStream(file); BufferedReader reader = new BufferedReader( charsetName == null ? new InputStreamReader(fis) : new InputStreamReader(fis, charsetName)); char[] chars = new char[DEFAULT_BUFFER_SIZE]; int numRead = 0; while ((numRead = reader.read(chars)) > -1) { sb.append(String.valueOf(chars, 0, numRead)); } reader.close(); return sb.toString(); } }