Java File Content Read getFileContents(File file)

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

Description

Get contents of a file as string.

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static String getFileContents(File file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileNotFoundException;

import java.util.Scanner;

public class Main {
    /**//from   w  ww .j a  va 2  s. c  o  m
     * Get contents of a file as string.
     * 
     * @param file
     * @return
     */
    public static String getFileContents(File file) {
        String content = "";
        try {
            Scanner scanner = new Scanner(file);
            content = scanner.useDelimiter("\\Z").next();
            scanner.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return content;
    }
}

Related

  1. getFileContent(String path)
  2. getFileContent(String path, String encoding)
  3. getFileContent(String pythonSource)
  4. getFileContents(File f)
  5. getFileContents(File f)
  6. getFileContents(File file)
  7. getFileContents(File methodPatch)
  8. getFileContents(File testFile)
  9. getFileContents(final File f)