Here you can find the source of readFile(String pPathToFile)
Parameter | Description |
---|---|
pPathToFile | path to file to read. |
Parameter | Description |
---|---|
IOException | an exception |
public static String readFile(String pPathToFile) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { /**// ww w.jav a 2 s.c o m * Read a file and return the content. * * @param pPathToFile * path to file to read. * @return String contained in the document. * @throws IOException */ public static String readFile(String pPathToFile) throws IOException { StringBuffer out = new StringBuffer(); FileInputStream inputStrem = new FileInputStream(new File(pPathToFile)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte buf[] = new byte[1024]; int len; while ((len = inputStrem.read(buf)) > 0) { outStream.write(buf, 0, len); out.append(outStream.toString()); } inputStrem.close(); outStream.close(); return out.toString(); } }