Here you can find the source of readFile(String file, String lineBreak)
public static String readFile(String file, String lineBreak)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String file) { return readFile(file, null); }// www.j a v a 2 s .c om public static String readFile(String file, String lineBreak) { File f = new File(file); return readFile(f, lineBreak); } public static String readFile(File file) { return readFile(file, null); } public static String readFile(File file, String lineBreak) { String lb = lineBreak == null ? "\r\n" : lineBreak; FileInputStream fis = null; InputStreamReader isr = null; BufferedReader br = null; StringBuilder buf = new StringBuilder(); try { fis = new FileInputStream(file); isr = new InputStreamReader(fis); br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { buf.append(line).append(lb); } } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (isr != null) { try { isr.close(); } catch (IOException e) { e.printStackTrace(); } } if (fis != null) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } return buf.toString(); } }