Here you can find the source of readFile(String path, Charset encoding)
Parameter | Description |
---|---|
path | path to the file. |
encoding | encoding to use. |
Parameter | Description |
---|---|
IOException | an exception |
@SuppressWarnings("resource") public static String readFile(String path, Charset encoding) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.Scanner; public class Main { /**/*from w w w .j a va 2 s.c om*/ * Read a file from path and convert it into string. (Method #1) * * @param path path to the file. * @param encoding encoding to use. * @return A string version of the input file. * @throws IOException */ @SuppressWarnings("resource") public static String readFile(String path, Charset encoding) throws IOException { return new Scanner(new File(path), "UTF-8").useDelimiter("\\A").next(); } }