Here you can find the source of getFileContents(Path file)
static public String getFileContents(Path file) throws IOException
//package com.java2s; /******************************************************************************* * SiniaUtils/*from ww w . ja va 2 s . co m*/ * Copyright (c) 2011-2 Siniatech Ltd * http://www.siniatech.com/products/siniautils * * All rights reserved. This project and the accompanying materials are made * available under the terms of the MIT License which can be found in the root * of the project, and at http://www.opensource.org/licenses/mit-license.php * ******************************************************************************/ import static java.nio.file.Files.*; import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Path; public class Main { static public String getFileContents(Path file) throws IOException { try (BufferedReader in = newBufferedReader(file, Charset.defaultCharset())) { StringBuffer sb = new StringBuffer(); String line; while ((line = in.readLine()) != null) { sb.append(line); } return sb.toString(); } } }