Here you can find the source of getFileContents(File f)
Parameter | Description |
---|---|
f | File object |
public static String getFileContents(File f) throws Exception
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { static final String lineSep = System.getProperty("line.separator"); /**// ww w .j av a2 s.c o m * getFileContents * * Build a string by concatenating all lines in File object. * * @param f File object * @return String */ public static String getFileContents(File f) throws Exception { FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); StringBuilder contents = new StringBuilder(); String line; while ((line = br.readLine()) != null) { contents.append(line + lineSep); } br.close(); return contents.toString(); } }