Java Path File Content getFileContents(Path file)

Here you can find the source of getFileContents(Path file)

Description

get File Contents

License

Open Source License

Declaration

static public String getFileContents(Path file) throws IOException 

Method Source Code

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

Related

  1. contentEquals(Path leftPath, Path rightPath)
  2. fileContent(final Path p)
  3. fileContent(final String filePath)
  4. getContent(Path path)
  5. getFileContents(final String absFilePath)
  6. getFileContents(String path)
  7. listUris(Path content)
  8. readContent(Path file)
  9. saveByteArrayToFile(byte[] content, Path targetPath)