Here you can find the source of readFile(String path)
Parameter | Description |
---|---|
path | The path to a text file. |
public static String readFile(String path)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { /**//from ww w .ja v a2s . c o m * Reads and returns the text contained in a given file. * * @param path * The path to a text file. * @return The text contained in the file. */ public static String readFile(String path) { StringBuilder res = new StringBuilder(); try { BufferedReader in = new BufferedReader(new FileReader(path)); String line = null; while ((line = in.readLine()) != null) { res.append(new String(line.getBytes(), "UTF-8") + "\n"); } in.close(); } catch (IOException e) { e.printStackTrace(); } return res.toString(); } }