Java Text File Read getFileContents(String filePath)

Here you can find the source of getFileContents(String filePath)

Description

get File Contents

License

Open Source License

Declaration

public static String getFileContents(String filePath) 

Method Source Code


//package com.java2s;
// License as published by the Free Software Foundation; either

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
    public static String getFileContents(String filePath) {
        try (InputStream stream = new FileInputStream(filePath)) {
            return getTextStreamContents(stream);
        } catch (final IOException ex) {
            throw new IllegalArgumentException(ex);
        }// w  w w  . ja va 2  s.  c  o m
    }

    public static String getTextStreamContents(InputStream input) {
        final Scanner scanner = new Scanner(input);
        scanner.useDelimiter("\\Z");
        return scanner.next();
    }
}

Related

  1. getFileContentAsString(File cpfile)
  2. getFileContentAsString(final String filePath)
  3. getFileContentAsString(InputStream inputStream)
  4. getFileContentAsString(String path)
  5. getFileContents(Reader reader)
  6. getFileContents(String filePath)
  7. getFileContents(String filePath)
  8. getFileContents(String filePath)
  9. getFileContents(String path)