Here you can find the source of getFileContents(String fileName)
public static synchronized String getFileContents(String fileName)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static synchronized String getFileContents(String fileName) { File file = new File(fileName); String results = null;/* w w w. j a v a 2 s . co m*/ try { int length = (int) file.length(), bytesRead; byte byteArray[] = new byte[length]; ByteArrayOutputStream bytesBuffer = new ByteArrayOutputStream(length); FileInputStream inputStream = new FileInputStream(file); bytesRead = inputStream.read(byteArray); bytesBuffer.write(byteArray, 0, bytesRead); inputStream.close(); results = bytesBuffer.toString(); } catch (IOException e) { System.out.println("Exception in getFileContents(" + fileName + "), msg=" + e); } return results; } }