Here you can find the source of slurpFileContent(Path path)
Parameter | Description |
---|---|
path | the path |
Parameter | Description |
---|---|
IOException | if an I/O error occurs |
public static String slurpFileContent(Path path) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 BestSolution.at and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*www. ja va2s.c o m*/ * Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation *******************************************************************************/ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; public class Main { /** * Read the content for the given path * * @param path * the path * @return the content * @throws IOException * if an I/O error occurs * @since 2.0 */ public static String slurpFileContent(Path path) throws IOException { byte[] buf = new byte[(int) Files.size(path)]; try (InputStream in = Files.newInputStream(path)) { in.read(buf); return new String(buf); } } }