Java Path File Content slurpFileContent(Path path)

Here you can find the source of slurpFileContent(Path path)

Description

Read the content for the given path

License

Open Source License

Parameter

Parameter Description
path the path

Exception

Parameter Description
IOException if an I/O error occurs

Return

the content

Declaration

public static String slurpFileContent(Path path) throws IOException 

Method Source Code

//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);
        }
    }
}

Related

  1. getFileContents(String path)
  2. listUris(Path content)
  3. readContent(Path file)
  4. saveByteArrayToFile(byte[] content, Path targetPath)
  5. saveFile(String workspacePath, byte[] content)
  6. write2File(String contents, Path outputPath)
  7. WriteContentsToFile(String planeTextFilePath, byte[] encryptedData)
  8. writeFile(final String content, final String path)
  9. writeFile(Path file, String content)