Here you can find the source of readTextFile(File path)
Parameter | Description |
---|---|
path | a parameter |
public static String readTextFile(File path)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { /**//w ww.j a v a2 s . c o m * Read a text file from a given path * @param path * @return */ public static String readTextFile(File path) { try { FileInputStream is = new FileInputStream(path); BufferedReader bin = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line = null; while ((line = bin.readLine()) != null) { sb.append(line); // re-add line separator sb.append(System.getProperty("line.separator")); } bin.close(); return sb.toString(); } catch (IOException e) { return null; } } }