Here you can find the source of readFile(File file)
Parameter | Description |
---|
public static String readFile(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static final String END_LINE = "\n"; /**/*ww w .ja va 2 s .c om*/ * This method read a whole file and return the content. * * @throws java.io.IOException when an error occurs while reading the file. */ public static String readFile(File file) throws IOException { if (!file.exists()) { throw new IllegalArgumentException("Illegal path: unexisting '" + file.getPath() + "'"); } if (!file.isFile()) { throw new IllegalArgumentException("Illegal path: not a dfile"); } FileReader fr = null; BufferedReader reader = null; StringBuffer buffer = new StringBuffer(); try { fr = new FileReader(file); reader = new BufferedReader(fr); String line = null; do { line = reader.readLine(); if (line != null) { buffer.append(line); buffer.append(END_LINE); } } while (line != null); } finally { reader.close(); fr.close(); } return buffer.toString(); } }