Java Scanner Read readFile(String filePath)

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

Description

Reads the file with the specified path as a String.

License

Open Source License

Declaration

public static String readFile(String filePath) throws IOException 

Method Source Code


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

import java.io.BufferedReader;

import java.io.FileReader;

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

public class Main {
    /**/*from  w  w w  .jav  a2s  . c o m*/
     * Reads the file with the specified path as a String.
     */
    public static String readFile(String filePath) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        Scanner sc = new Scanner(br);
        try {
            return sc.useDelimiter("\\Z").next();
        } finally {
            sc.close();
            br.close();
        }
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String fileName)
  3. readFile(String fileName)
  4. readFile(String filePath)
  5. readFile(String filePath)
  6. readFile(String path)
  7. readFile(String pathname)
  8. readFile(String project, boolean judge)
  9. readFileFully(InputStream stream)