Here you can find the source of getFileContent(final File srcFile)
Parameter | Description |
---|---|
srcFile | File |
Parameter | Description |
---|---|
IOException | an exception |
public static String getFileContent(final File srcFile) throws IOException
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { /**/*from w w w . j ava 2 s . com*/ * Returns the content of a file as string. * * @param srcFile * File * @return String * @throws IOException */ public static String getFileContent(final File srcFile) throws IOException { if ((srcFile != null) && srcFile.exists() && srcFile.isFile()) { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(srcFile))); StringBuffer contentOfFile = new StringBuffer(); String line; while ((line = br.readLine()) != null) { contentOfFile.append(line); } return contentOfFile.toString(); } return null; } }