Here you can find the source of readFile(File f, String newLineChar)
public static String readFile(File f, String newLineChar) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from ww w.j a v a 2 s . com*/ * Reads contents of file (f) into a String (up to five megs) */ public static String readFile(File f) throws IOException { return readFile(f, "\n"); } public static String readFile(File f, int startLine, int numRowsToRead) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(f)); for (int i = 1; i < startLine; i++) { reader.readLine(); } StringBuilder rtn = new StringBuilder(); counter: for (int i = 0; i < numRowsToRead; i++) { String line = reader.readLine(); if (line != null) { rtn.append(line); } else { break counter; } } reader.close(); return rtn.toString(); } /** * Reads contents of file (f) into a String (up to five megs) using newLineChar as a line seperator */ public static String readFile(File f, String newLineChar) throws IOException { if (f.length() > 5000000) return "File too long"; BufferedReader buf = new BufferedReader(new FileReader(f)); StringBuffer results = new StringBuffer(); while (buf.ready()) { results.append(buf.readLine()).append(newLineChar); } return results.toString(); } }