Here you can find the source of readFileToString(String pathToFile)
public static String readFileToString(String pathToFile)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; public class Main { public static String readFileToString(String pathToFile) { byte[] buffer = readFileToByteArray(pathToFile); if (buffer != null) { return new String(buffer); }/*from w ww. ja v a 2 s . c o m*/ return null; } public static byte[] readFileToByteArray(String pathToFile) { byte[] result = null; try { File file = new File(pathToFile); if (file.length() <= Integer.MAX_VALUE) { result = new byte[(int) file.length()]; @SuppressWarnings("resource") RandomAccessFile raf = new RandomAccessFile(file, "r"); raf.readFully(result); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } }