Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
IOException | an exception |
public static String readFile(File file) throws IOException
//package com.java2s; import java.io.*; public class Main { /**/*from w w w . j av a 2s . c o m*/ * Read file contents as a string * @throws IOException */ public static String readFile(File file) throws IOException { StringWriter s = new StringWriter(); char[] buff = new char[1000]; FileReader in = new FileReader(file); try { int read = 0; while ((read = in.read(buff)) >= 0) { s.write(buff, 0, read); } } finally { in.close(); } return s.toString(); } }