Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | input file |
Parameter | Description |
---|---|
IOException | an exception |
private static String readFile(File file) throws IOException
//package com.java2s; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /**/* ww w. j a v a 2 s.co m*/ * Helper function to read the contents of a file and return a string represntation. * * @param file input file * * @throws IOException */ private static String readFile(File file) throws IOException { FileReader fileReader = new FileReader(file); StringBuffer content = new StringBuffer(); int read = fileReader.read(); while (read != -1) { content.append((char) read); read = fileReader.read(); } return content.toString(); } }