Here you can find the source of fileToString(String fileName)
public static String fileToString(String fileName)
//package com.java2s; //License from project: Apache License import java.io.FileInputStream; public class Main { /**/*from w w w. j av a 2s. c om*/ * Converts a file specified by the path, to the String. */ public static String fileToString(String fileName) { if (fileName != null) { // String sLine; byte[] utf8Bytes; String sFile = new String(); // Reading input by lines: try { FileInputStream fis = new FileInputStream(fileName); int noOfBytes = fis.available(); if (noOfBytes > 0) { utf8Bytes = new byte[noOfBytes]; fis.read(utf8Bytes); sFile = new String(utf8Bytes, "UTF8"); } } catch (Exception ex) { return null; } return sFile; } return null; } }