Here you can find the source of readFile(String filename)
Parameter | Description |
---|---|
filename | a parameter |
Parameter | Description |
---|
public static String readFile(String filename) throws java.io.IOException
//package com.java2s; import java.io.*; public class Main { /**/*w w w . j a va2 s . com*/ * Read a file into a string * * @param filename * @return * @throws java.io.IOException */ public static String readFile(String filename) throws java.io.IOException { StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new FileReader(filename)); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; } reader.close(); return fileData.toString(); } }