Here you can find the source of loadTextFile(File textFile)
public static String loadTextFile(File textFile)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static String loadTextFile(File textFile) { try {/*from ww w .j ava 2 s .c o m*/ try (FileInputStream fileStream = new FileInputStream(textFile)) { return new String(loadBytes(fileStream)); } } catch (IOException e) { throw new RuntimeException(e); } } public static byte[] loadBytes(InputStream inputStream) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[16384]; while ((nRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); return buffer.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } } }