public String getFileContentsAsString(final File file, final String encoding)
			throws IOException {
		LOG.info("Getting files contents as string: " + file);
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(new FileInputStream(
					file), encoding));

			StringBuilder builder = new StringBuilder();

			String line = null;
			while ((line = br.readLine()) != null) {
				builder.append(line);
			}

			LOG.debug("File contents: " + builder);
			return builder.toString();
		} finally {
			if (br != null) {
				br.close();
			}
		}
	}
public String getFileContentsAsString ( final File file , final String encoding ) throws IOException { LOG . info ( "Getting files contents as string: " + file ) ; BufferedReader br = null ; try { br = new BufferedReader ( new InputStreamReader ( new FileInputStream ( file ) , encoding ) ) ; StringBuilder builder = new StringBuilder ( ) ; String line = null ; while ( ( line = br . readLine ( ) ) != null ) { builder . append ( line ) ; } LOG . debug ( "File contents: " + builder ) ; return builder . toString ( ) ; } finally { if ( br != null ) { br . close ( ) ; } } }
Returns the contents of a file into a String object. <br/>
Please be careful when using this with large files

@param file
the file
@param encoding
the file encoding. Example: "UTF-8", "UTF-16"
@return a String object with the contents of the file
@throws IOException
if something goes wrong while reading the file