Here you can find the source of getFileContents(String pathToFile)
Parameter | Description |
---|---|
pathToFile | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String getFileContents(String pathToFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**/*from w ww . java 2s.c om*/ * FileUtils.getFileContents() * * Returns the content of a file as a String * * @param pathToFile * @return * @throws IOException */ public static String getFileContents(String pathToFile) throws IOException { BufferedReader br = null; String content = ""; try { String sCurrentLine; br = new BufferedReader(new FileReader(pathToFile)); while ((sCurrentLine = br.readLine()) != null) { content += sCurrentLine + "\r\n"; } } finally { if (br != null) br.close(); } return content; } }