Here you can find the source of readTextFile(File path, String encoding)
public static StringBuffer readTextFile(File path, String encoding)
//package com.java2s; /**//from w w w .jav a2 s. com * Copyright(c) 2005 Dragonfly - created by FengChun * All Rights Reserved. * * @license: Dragonfly Common License * @date 2005-5-16 */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static StringBuffer readTextFile(File path, String encoding) { StringBuffer sb = new StringBuffer(""); InputStreamReader read = null; BufferedReader reader = null; try { read = new InputStreamReader(new FileInputStream(path), encoding); reader = new BufferedReader(read); String line; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (Exception e) { e.printStackTrace(); } finally { if (read != null) try { read.close(); } catch (IOException e) { } if (reader != null) try { reader.close(); } catch (IOException e) { } } return sb; } }